T - comparable typepublic class SerializableComparatorWrapperClass<T> extends Object implements SerializableComparator<T>
Comparator, such as Collator.
This way you can still use such comparators in a serializable way.
This wrapper calls the given SerializableSupplier to retrieve a delegate Comparator which it
uses for all calls to its compare(Object, Object)-method. It caches the retrieved Comparator
in a transient field for efficiency.
Usage example:
(Note that Collator is an instance of Comparator typed with Object, not with a generic type variable.)SerializableComparator<Object> collator = new SerializableComparatorWrapper<>(() -> Collator.getInstance(Locale.UK)); SerializableComparator<Object> objectComparator = SerializableComparator.comparing(Object::toString, collator);
| Constructor and Description |
|---|
SerializableComparatorWrapperClass(SerializableSupplier<Comparator<T>> comparatorSupplier) |
| Modifier and Type | Method and Description |
|---|---|
int |
compare(T o1,
T o2) |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitcomparing, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongcomparing, comparing, comparingDouble, comparingInt, comparingLong, equals, nullsFirst, nullsLast, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongpublic SerializableComparatorWrapperClass(SerializableSupplier<Comparator<T>> comparatorSupplier)
public int compare(T o1, T o2)
compare in interface Comparator<T>Copyright © 2019. All rights reserved.