If you intend to sort() your arrays or collections by some numerical value, you can make your classes implements
DoubleSupplier:
import java.util.function.DoubleSupplier;
class SomeClass implements DoubleSupplier {
float x;
@Override double getAsDouble() {
return x;
}
}
And use the Comparator below in order to sort() by ascending numerical order:
import java.util.Comparator;
import java.util.function.DoubleSupplier;
import java.util.Arrays;
import java.util.Collections;
static final Comparator<DoubleSupplier> ASCENT = new Comparator<DoubleSupplier>() {
@Override final int compare(final DoubleSupplier d1, final DoubleSupplier d2) {
return (int) Math.signum(d1.getAsDouble() - d2.getAsDouble());
}
};