Class ArraysExt.ArrayComparator<O>

  • Type Parameters:
    O - Some object type to be compared.
    All Implemented Interfaces:
    Comparator<O[]>
    Enclosing class:
    ArraysExt<E>

    static class ArraysExt.ArrayComparator<O>
    extends Object
    implements Comparator<O[]>
    Comparator class which implements a kind of lexical ordering on arrays based on the ordering of the components defined by atomic.
    • Constructor Detail

      • ArrayComparator

        ArrayComparator​(Comparator<Object> atomic)
        Creates a new ArrayComparator to compare two object-arrays by lexical ordering. Here, the orderin of the components is defined by atomic.
        Parameters:
        atomic - a Comparator for components of an array.
    • Method Detail

      • compare

        public int compare​(Object[] arr1,
                           Object[] arr2)
        Describe compare method here.
        Specified by:
        compare in interface Comparator<O>
        Parameters:
        arr1 - an Object[] object. The components o1[i] and o2[i] must be pairwise comparable with respect to atomic provided both o1[i] and o2[i] exist.
        arr2 - an Object[] object. The components o1[i] and o2[i] must be pairwise comparable with respect to atomic provided both o1[i] and o2[i] exist.
        Returns:
        • 0 if and only if o1.length == o2.length and atomic.compare(o1[i], o2[i]) == 0 for all indices i. Hence this comparator is consistent with equals if and only if this is true for atomic.
        • -1 resp.1 if o1 is a true prefix of o2 res. the other way round.
        • atomic.compare(o1[i], o2[i]) where i is the lowest index such that atomic.compare(o1[i], o2[i]) != 0. (Provided such an index in the common range exists. )
        Throws:
        NullPointerException - if one of the arguments is null.
        ClassCastException - if one of the arguments is no Object[]. in particular for type int[].