- 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.
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 Summary
Modifier and TypeMethodDescriptionint
Compares the components ofa
andb
at the givenindex
.default <T> ElementComparator
<T> Return an element comparator for the mapped typeT
.default Comparator
<V> ofIndex
(int index) Return a comparator which takes the component at the giveindex
for comparison two objects of typeT
.default ElementComparator
<V> reversed()
Returns a comparator that imposes the reverse ordering of this comparator.
-
Method Details
-
compare
Compares the components ofa
andb
at the givenindex
. E.g.final ElementComparator<double[]> comp = (u, v, i) -> Double.compare(u[i], v[i]);
- Parameters:
u
- the first vectorv
- the second vectorindex
- 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 eithera
orb
isnull
IndexOutOfBoundsException
- if the index is out of range(index < 0 || index >= length(a) || index >= length(b))
-
reversed
Returns a comparator that imposes the reverse ordering of this comparator.- Returns:
- a comparator that imposes the reverse ordering of this comparator.
-
map
Return an element comparator for the mapped typeT
.- Type Parameters:
T
- the new comparator type- Parameters:
mapper
- the mapper function- Returns:
- an element comparator for the mapped type
T
-
ofIndex
Return a comparator which takes the component at the giveindex
for comparison two objects of typeT
.- Parameters:
index
- the component index- Returns:
- the component comparator for the given
index
-