Class TaggableComparator

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

    public class TaggableComparator
    extends java.lang.Object
    implements java.util.Comparator<Taggable>
    FIXME: Wrong description!!! A comparator imposing an ordering on Unit objects by comparing the factions they belong to.

    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 units belong to the same faction 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
      TaggableComparator​(java.lang.String tag, java.util.Comparator<? super Taggable> subComparator)
      Creates a new TagBasedComparatorComparator object with the default tag "ejcTagBasedComparatorTag"
      TaggableComparator​(java.util.Comparator<? super Taggable> subComparator)
      Creates a new TagBasedComparatorComparator object with the default tag "ejcTagBasedComparatorTag"
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(Taggable o1, Taggable o2)
      Compares its two arguments for order according to the factions they belong to.
      • 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

      • subCmp

        protected java.util.Comparator<? super Taggable> subCmp
      • tagToCompare

        protected java.lang.String tagToCompare
    • Constructor Detail

      • TaggableComparator

        public TaggableComparator​(java.util.Comparator<? super Taggable> subComparator)
        Creates a new TagBasedComparatorComparator object with the default tag "ejcTagBasedComparatorTag"
        Parameters:
        subComparator - the comparator used to compare the Tagged tags if this one thinks they are equal
      • TaggableComparator

        public TaggableComparator​(java.lang.String tag,
                                  java.util.Comparator<? super Taggable> subComparator)
        Creates a new TagBasedComparatorComparator object with the default tag "ejcTagBasedComparatorTag"
        Parameters:
        subComparator - the comparator used to compare the Tagged tags if this one thinks they are equal
        tag - to compare the two Tagged objects
    • Method Detail

      • compare

        public int compare​(Taggable o1,
                           Taggable o2)
        Compares its two arguments for order according to the factions they belong to.
        Specified by:
        compare in interface java.util.Comparator<Taggable>
        Returns:
        the result of the faction comparator's comparison of o1's and o2. If both belong to the same faction and a sub-comparator was specified, the result that sub-comparator's comparison is returned. Undefined values are evaluated as > 0.