Interface ElementComparator<V>

  • Type Parameters:
    V - the vector type
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface ElementComparator<V>
    Defines the order of two elements of a given vector type V. The following example creates an ElementComparator function for a double[] array:
    final ElementComparator<double[]> comp = (u, v, i) -> Double.compare(u[i], v[i]);
    Since:
    4.1
    Version:
    4.1
    • Method Detail

      • compare

        int compare​(V u,
                    V v,
                    int index)
        Compares the components of a and b at the given index. E.g.
        final ElementComparator<double[]> comp = (u, v, i) -> Double.compare(u[i], v[i]);
        Parameters:
        u - the first vector
        v - the second vector
        index - the vector index
        Returns:
        a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.
        Throws:
        NullPointerException - if either a or b is null
        IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= length(a) || index >= length(b))
      • reversed

        default ElementComparator<Vreversed()
        Returns a comparator that imposes the reverse ordering of this comparator.
        Returns:
        a comparator that imposes the reverse ordering of this comparator.
      • map

        default <T> ElementComparator<T> map​(Function<? super T,​? extends V> mapper)
        Return an element comparator for the mapped type T.
        Type Parameters:
        T - the new comparator type
        Parameters:
        mapper - the mapper function
        Returns:
        an element comparator for the mapped type T
      • ofIndex

        default Comparator<VofIndex​(int index)
        Return a comparator which takes the component at the give index for comparison two objects of type T.
        Parameters:
        index - the component index
        Returns:
        the component comparator for the given index