Class FactionTrustComparator

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

    public class FactionTrustComparator
    extends java.lang.Object
    implements java.util.Comparator<Faction>
    A comparator imposing an ordering on Faction objects by comparing the 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.

    • Constructor Summary

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(Faction o1, Faction o2)
      Compares its two arguments for order with regard to their trust levels (one of PRIVILEGED, ALLIED, DEFAULT, or ENEMY.
      static int getTrustLevel​(int trustLevel)
      Returns the trust level (privilegd,allied,default,enemy) for an exact trust value.
      static int getTrustLevel​(Faction f)
      Returns the trust level (privilegd,allied,default,enemy) of a faction.
      static java.lang.String getTrustLevelLabel​(int level)
      Returns the name of a trust level (privilegd,allied,default,enemy).
      • 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
      • DEFAULT_COMPARATOR

        public static final FactionTrustComparator DEFAULT_COMPARATOR
        A convenient constant providing a comparator that just compares the trust level (privilegd,allied,default,enemy)
      • DETAILED_COMPARATOR

        public static final FactionTrustComparator DETAILED_COMPARATOR
        A convenient constant providing a comparator that just compares the exact trust value
      • PRIVILEGED

        public static final int PRIVILEGED
        The "privileged" trust level
        See Also:
        Constant Field Values
    • Constructor Detail

      • FactionTrustComparator

        public FactionTrustComparator​(java.util.Comparator<? super Faction> sameFactionSubComparator)
        Creates a new FactionTrustComparator 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 its two arguments for order with regard to their trust levels (one of PRIVILEGED, ALLIED, DEFAULT, or ENEMY.
        Specified by:
        compare in interface java.util.Comparator<Faction>
        Parameters:
        o1 -
        o2 -
        Returns:
        the difference of o2's and o1's trust level values. If this is 0 and a sub-comparator is specified, the result of that sub-comparator's comparison is returned. Unknown values are evaluated as > 0.
      • getTrustLevel

        public static int getTrustLevel​(Faction f)
        Returns the trust level (privilegd,allied,default,enemy) of a faction.
        Parameters:
        f -
        Returns:
        Returns the trust level of a faction
      • getTrustLevel

        public static int getTrustLevel​(int trustLevel)
        Returns the trust level (privilegd,allied,default,enemy) for an exact trust value.
        Parameters:
        trustLevel -
        Returns:
        Returns the trust level for an exact trust value.
      • getTrustLevelLabel

        public static java.lang.String getTrustLevelLabel​(int level)
        Returns the name of a trust level (privilegd,allied,default,enemy).
        Parameters:
        level - One of the defined levels
        Returns:
        Returns the name of the trust level