Class Comparators.AsListed<E>

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

    private static class Comparators.AsListed<E>
    extends Object
    implements Comparator<E>, 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.

    • Constructor Detail

      • AsListed

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

      • compare

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