Class SerializableComparatorWrapperClass<T>
java.lang.Object
org.danekja.java.misc.serializable.SerializableComparatorWrapperClass<T>
- Type Parameters:
T- comparable type
- All Implemented Interfaces:
Serializable,Comparator<T>,SerializableComparator<T>
public class SerializableComparatorWrapperClass<T>
extends Object
implements SerializableComparator<T>
Wrapper for a non-serializable subclass of
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);
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate SerializableSupplier<Comparator<T>> private Comparator<T> private static final long -
Constructor Summary
ConstructorsConstructorDescriptionSerializableComparatorWrapperClass(SerializableSupplier<Comparator<T>> comparatorSupplier) -
Method Summary
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.Comparator
equals, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongMethods inherited from interface org.danekja.java.misc.serializable.SerializableComparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
comparatorSupplier
-
delegate
-
-
Constructor Details
-
SerializableComparatorWrapperClass
-
-
Method Details
-
compare
- Specified by:
comparein interfaceComparator<T>
-