Class UnitHealthComparator

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

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

    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.

    Author:
    Ulrich Küster
    • Field Summary

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

      Constructors 
      Constructor Description
      UnitHealthComparator​(java.util.Comparator<? super Unit> subComparator)
      Creates a new UnitHealthComparator object.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(Unit u1, Unit u2)
      Compares its two arguments for order according to the health-status.
      • 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 Unit> subCmp
    • Constructor Detail

      • UnitHealthComparator

        public UnitHealthComparator​(java.util.Comparator<? super Unit> subComparator)
        Creates a new UnitHealthComparator object.
        Parameters:
        subComparator - if two units have the same health-status, this sub-comparator is applied if it is not null.
    • Method Detail

      • compare

        public int compare​(Unit u1,
                           Unit u2)
        Compares its two arguments for order according to the health-status. Unlike other comparators in this package, unknown values are evaluated as < 0.
        Specified by:
        compare in interface java.util.Comparator<Unit>