Class UnitSkillComparator

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

    public class UnitSkillComparator
    extends java.lang.Object
    implements java.util.Comparator<Unit>
    A comparator imposing an ordering on Unit objects by comparing their skills.

    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.

    • Constructor Summary

      Constructors 
      Constructor Description
      UnitSkillComparator​(java.util.Comparator<? super java.util.Map<? extends ID,​Skill>> skillsComparator, java.util.Comparator<? super Unit> subComparator)
      Creates a new UnitSkillComparator object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(Unit o1, Unit o2)
      Compares its two arguments for order according to their skills.
      • 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
    • Constructor Detail

      • UnitSkillComparator

        public UnitSkillComparator​(java.util.Comparator<? super java.util.Map<? extends ID,​Skill>> skillsComparator,
                                   java.util.Comparator<? super Unit> subComparator)
        Creates a new UnitSkillComparator object.
        Parameters:
        skillsComparator - used to compare the skills of two units
        subComparator - if two units do not possess skills or if the skills comparator regards them as equal, this sub-comparator is applied if it is not null.
    • Method Detail

      • compare

        public int compare​(Unit o1,
                           Unit o2)
        Compares its two arguments for order according to their skills. The learning days of the best skill of unit one is compared to those of the second unit.
        Specified by:
        compare in interface java.util.Comparator<Unit>
        Returns:
        a number < 0 if o1's best skill is alphabetically less than o2's best skill. If both units have the same best skill these are compared using the standard skill comparator. If these two values are the same, the subcomparator is used to compare the two units. Unknown values are evaluated as > 0.