Class FactionDetailComparator

  • All Implemented Interfaces:
    java.util.Comparator<Faction>

    public class FactionDetailComparator
    extends java.lang.Object
    implements java.util.Comparator<Faction>
    A comparator imposing an ordering on Faction objects by comparing their exact trust levels.

    Note: this comparator imposes orderings that are inconsistent with equals.

    In order to overcome the inconsistency with equals this comparator allows the introduction of a sub-comparator which is applied in cases of equality. I.e. if the two compared factions belong to the same trust level and they would be regarded as equal by this comparator, instead of 0 the result of the sub-comparator's comparison is returned.

    Author:
    stm
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Comparator<? super Faction> sameTrustSubCmp  
    • Constructor Summary

      Constructors 
      Constructor Description
      FactionDetailComparator​(java.util.Comparator<? super Faction> sameFactionSubComparator)
      Creates a new FactionDetailComparator object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(Faction o1, Faction o2)
      Compares the exact trust levels of the two factions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface java.util.Comparator

        equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
    • Field Detail

      • sameTrustSubCmp

        protected java.util.Comparator<? super Faction> sameTrustSubCmp
    • Constructor Detail

      • FactionDetailComparator

        public FactionDetailComparator​(java.util.Comparator<? super Faction> sameFactionSubComparator)
        Creates a new FactionDetailComparator object.
        Parameters:
        sameFactionSubComparator - if two factions with the same trust level are compared, this sub-comparator is applied if it is not null.
    • Method Detail

      • compare

        public int compare​(Faction o1,
                           Faction o2)
        Compares the exact trust levels of the two factions.
        Specified by:
        compare in interface java.util.Comparator<Faction>
        See Also:
        Comparator.compare(java.lang.Object, java.lang.Object)