Class UnitRegionComparator

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

    public class UnitRegionComparator
    extends java.lang.Object
    implements java.util.Comparator<Unit>
    A comparator imposing an ordering on Unit objects by comparing the regions they are in.

    Note: this comparator can impose orderings that are inconsistent with equals.

    • Constructor Summary

      Constructors 
      Constructor Description
      UnitRegionComparator​(java.util.Comparator<? super Region> regionSubComparator, java.util.Comparator<? super Unit> sameRegionSubComparator)
      Creates a new UnitRegionComparator 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 the regions 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

      • regionSubCmp

        protected java.util.Comparator<? super Region> regionSubCmp
      • sameRegionSubCmp

        protected java.util.Comparator<? super Unit> sameRegionSubCmp
    • Constructor Detail

      • UnitRegionComparator

        public UnitRegionComparator​(java.util.Comparator<? super Region> regionSubComparator,
                                    java.util.Comparator<? super Unit> sameRegionSubComparator)
        Creates a new UnitRegionComparator object.
        Parameters:
        regionSubComparator - is used to compare the regions that two units to be compared belong to. If regionSubComparators regards the regions as equal, the comparator sameRegionSubComparator is applied.
        sameRegionSubComparator - is applied if the regionSubComparator regards two units equal according to the regions they are in.
    • Method Detail

      • compare

        public int compare​(Unit o1,
                           Unit o2)
        Compares its two arguments for order according to the regions they belong to.
        Specified by:
        compare in interface java.util.Comparator<Unit>
        Returns:
        the result of the region sub-comparator applied to the regions of the the two units o1 and o2 or the result of the sameRegion sub-comparator if the afore-said comparator regards the units' regions as equal. Unknown values are evaluated as > 0.