Class LinearUnitTempUnitComparator

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

    public class LinearUnitTempUnitComparator
    extends java.lang.Object
    implements java.util.Comparator<Unit>
    A comparator imposing an ordering on Unit and TempUnit objects by sorting all temp units behind normal units.

    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 are either both normal units or both temp units, instead of 0 the result of the unit sub-comparator's comparison is returned.

    • Field Summary

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

      Constructors 
      Constructor Description
      LinearUnitTempUnitComparator​(java.util.Comparator<? super Unit> unitSubComparator)
      Creates a new LinearUnitTempUnitComparator 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 their types.
      • 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

      • LinearUnitTempUnitComparator

        public LinearUnitTempUnitComparator​(java.util.Comparator<? super Unit> unitSubComparator)
        Creates a new LinearUnitTempUnitComparator object.
        Parameters:
        unitSubComparator - if two units are of the same type (standard or temp unit), 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 their types.
        Specified by:
        compare in interface java.util.Comparator<Unit>
        Returns:
        a value less than zero if o1 is.an instance of class Unit and o2 an instance of class TempUnit. Conversely, if o1 is an instance of class TempUnit and o2 an instance of class Unit, a value greater than zero is returned. If o1 and o2 are instances of the same class, the comparison either returns zero or, when unitSubComparator is not null, that comparator's result.