![JAR search and dependency download from the Maven repository](/logo.png)
comparators.LongComparator Maven / Gradle / Ivy
package net.mintern.primitive.comparators;
/**
* A comparison function that imposes total ordering on {@code long} values.
*
* This is a {@code @FunctionalInterface} even though it isn't declared as one,
* so that it can be used in Java 6+.
*/
public interface LongComparator {
/**
* Compares {@code l1} and {@code l2}. Returns a negative value to indicate
* that {@code l1 < l2}, 0 to indicate that {@code l1 == l2}, and a positive
* value to indicate that {@code l1 > l2}.
*
* Implementations of this method must maintain the following invariants:
*
* - {@code s(compare(x, y)) == -s(compare(y, x))}
*
- {@code s(compare(x, y)) == s(compare(y, z))} →
* {@code s(compare(x, y)) == s(compare(x, z))} (transitivity)
*
- {@code compare(x, y) == 0} →
* {@code s(compare(x, z)) == s(compare(y, z))} ∀ {@code z}
*
*
* where {@code s(x)} is defined as follows:
*
* - {@code x < 0}: -1
*
- {@code x == 0}: 0
*
- {@code x > 0}: 1
*
*
* @param l1 the first long to compare
* @param l2 the second long to compare
* @return a negative value, 0, or a positive value to indicate that
* {@code l1} is less than, equal to, or greater than {@code l2},
* respectively
*/
int compare(long l1, long l2);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy