Class Comparators.AsListed<E>

  • Type Parameters:
    E - the type to be compared.
    All Implemented Interfaces:
    java.io.Serializable, java.util.Comparator<E>
    Enclosing class:
    Comparators<E>

    private static class Comparators.AsListed<E>
    extends java.lang.Object
    implements java.util.Comparator<E>, java.io.Serializable
    Implements an ordering given by the list seq. Elements not in the list are all minimal and pairwise equal with respect to this comparator. They are less than all elements in the list. The ordering on the list is ascending.

    CAUTION: This ordering is consistent with equals only if the elements of seq are pairwise non-equal. If this condition is hurt, an element a may satisfy a>a. Even if this condition is satisfied, two elements a, b not in seq satisfy a=b with respect to the ordering even if they are not equal with respect to the method Object.equals(Object). Thus the ordering is consistent with equals only, if restricted to the elements of seq plus one single object not in seq. This suffices to make the method Set.add(Object) to work properly.

    The ordering is always total, i.e. either a\le b or b\le a holds. This is clear if both elements are in seq and also if one is not. Also the ordering is always transitive: Assume a\le b or b\le c. If a\not\in seq, then a\le c. If b\not\in seq then also a\not\in seq. Ifc\not\in seq then also b\not\in seq. So, if one of the elements is not in seq, transitivity holds. Otherwise, all elements are in seq and transitivity follows directly.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.List<E> seq  
      private static long serialVersionUID  
    • Constructor Summary

      Constructors 
      Constructor Description
      AsListed​(java.util.List<E> seq)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compare​(E obj1, E obj2)  
      • 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

      • seq

        private final java.util.List<E> seq
    • Constructor Detail

      • AsListed

        AsListed​(java.util.List<E> seq)
    • Method Detail

      • compare

        public int compare​(E obj1,
                           E obj2)
        Specified by:
        compare in interface java.util.Comparator<E>