Class BaseComparator<T>
java.lang.Object
overit.geocallapp.utilities.core.bl.BaseComparator<T>
- Type Parameters:
T- the type of objects that may be compared by this comparator
- All Implemented Interfaces:
Comparator<T>
- Direct Known Subclasses:
SchedulingCancellingComparator
Abstract base class for null-safe comparators.
This class provides a foundation for implementing
This class provides a foundation for implementing
Comparator with built-in
null-safety handling. It automatically manages null value comparisons according to
a consistent strategy:
- If both objects are null, they are considered equal (returns 0)
- If only the first object is null, it is considered greater (returns 1)
- If only the second object is null, it is considered lesser (returns -1)
- If both objects are non-null, delegates to the
safeCompare(Object, Object)method
- Since:
- 1.0
-
Constructor Summary
Constructors -
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, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Constructor Details
-
BaseComparator
public BaseComparator()
-
-
Method Details
-
compare
Compares two objects with automatic null-safety handling. This method implements theComparator.compare(Object, Object)contract with built-in null value handling. The comparison logic is:- If both objects are null: returns 0 (equal)
- If only o1 is null: returns 1 (o1 > o2)
- If only o2 is null: returns -1 (o1 < o2)
- If both are non-null: delegates to
safeCompare(Object, Object)
- Specified by:
comparein interfaceComparator<T>- Parameters:
o1- the first object to be comparedo2- the second object to be compared- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second
-
safeCompare
Compares two non-null objects. This method is called bycompare(Object, Object)when both objects are guaranteed to be non-null. Subclasses must implement this method to provide the specific comparison logic for their object type.- Parameters:
t1- the first non-null object to be comparedt2- the second non-null object to be compared- Returns:
- a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second
-