Package io.jenetics.ext.moea
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 typeV
. The following example creates anElementComparator
function for adouble[] array
:final ElementComparator<double[]> comp = (u, v, i) -> Double.compare(u[i], v[i]);
- Since:
- 4.1
- Version:
- 4.1
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description int
compare(V u, V v, int index)
Compares the components ofa
andb
at the givenindex
.default <T> ElementComparator<T>
map(Function<? super T,? extends V> mapper)
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 Detail
-
compare
int compare(V u, V v, int index)
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
default ElementComparator<V> reversed()
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 typeT
.- Type Parameters:
T
- the new comparator type- Parameters:
mapper
- the mapper function- Returns:
- an element comparator for the mapped type
T
-
ofIndex
default Comparator<V> ofIndex(int index)
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
-
-