public interface ComparisonContext<T> extends Equator<T>, Comparator<T>
Equator. Typical implementations compare() throw an
IllegalArgumentException if one parameter is null (if both are null, it's probably OK to return 0).
More at eq(Object, Object).
A common mistake is to implement a ComparisonContext, Equator, or Comparator as an anonymous class
or lambda, then be surprised when it is can't be serialized, or is deserialized as null. These
one-off classes are often singletons, which are easiest to serialize as enums. If your
implementation requires generic type parameters, look at how defCompCtx() tricks the type
system into using generic type parameters (correctly) with an enum.| Modifier and Type | Interface and Description |
|---|---|
static class |
ComparisonContext.CompCtx |
Equator.Comp, Equator.Equat| Modifier and Type | Method and Description |
|---|---|
static <T> ComparisonContext<T> |
defCompCtx() |
default boolean |
eq(T o1,
T o2)
The default implementation of this method returns false if only one parameter is null then
checks if compare() returns zero.
|
default boolean |
gt(T o1,
T o2)
Returns true if the first object is greater than the second.
|
default boolean |
gte(T o1,
T o2)
Returns true if the first object is greater than or equal to the second.
|
default boolean |
lt(T o1,
T o2)
Returns true if the first object is less than the second.
|
default boolean |
lte(T o1,
T o2)
Returns true if the first object is less than or equal to the second.
|
defaultComparator, defaultEquator, hashcompare, comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongdefault boolean lte(T o1, T o2)
default boolean gte(T o1, T o2)
default boolean eq(T o1, T o2)
static <T> ComparisonContext<T> defCompCtx()
Copyright © 2017. All rights reserved.