Class MessageTypeSectionComparator

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

    public class MessageTypeSectionComparator
    extends java.lang.Object
    implements java.util.Comparator<MessageType>
    A comparator imposing an ordering on MessageType objects by comparing the sections (categories) 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 messages belong to the same section 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
      MessageTypeSectionComparator​(java.util.Comparator<MessageType> sameSectionSubComparator)
      Creates a new MessageTypeSectionComparator object.
    • Method Summary

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

      • sameSectionSubCmp

        protected java.util.Comparator<MessageType> sameSectionSubCmp
    • Constructor Detail

      • MessageTypeSectionComparator

        public MessageTypeSectionComparator​(java.util.Comparator<MessageType> sameSectionSubComparator)
        Creates a new MessageTypeSectionComparator object.
        Parameters:
        sameSectionSubComparator - if two messages belonging to the same section are compared, this sub-comparator is applied if it is not null.
    • Method Detail

      • compare

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