Class AbstractComparator<T>
java.lang.Object
org.deltava.comparators.AbstractComparator<T>
- Type Parameters:
T
- the object class
- All Implemented Interfaces:
Serializable
,Comparator<T>
- Direct Known Subclasses:
AirlineComparator
,AirportComparator
,CountryComparator
,EquipmentComparator
,FlightReportComparator
,GateComparator
,PerformanceComparator
,PersonComparator
,RequestCounterComparator
,ScheduleEntryComparator
,StaffComparator
,TestComparator
Implements common comparator functions.
NOTE: Most comparators in this package impose orderings that are inconsistent with equals.
- Since:
- 1.0
- Version:
- 7.2
- Author:
- Luke
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected int
The criteria by which to compare objects.protected String[]
Text descriptions of the different comparison types. -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
AbstractComparator
(String[] typeNames) Create a new comparator with a given set of type names. -
Method Summary
Modifier and TypeMethodDescriptionfinal int
Return the result by interrogating the implementation and applying a reverse sort if requred.protected abstract int
compareImpl
(T o1, T o2) This method does the actual comparison.int
Return the comparison type.String[]
Return the list of comparison type names.void
setComparisonType
(int type) Sets the comparison type.void
setComparisonType
(String type) Sets the comparison type.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
_comparisonType
protected int _comparisonTypeThe criteria by which to compare objects. -
_typeNames
Text descriptions of the different comparison types.
-
-
Constructor Details
-
AbstractComparator
Create a new comparator with a given set of type names.- Parameters:
typeNames
- An array of type names- Throws:
NullPointerException
- if typeNames is null
-
-
Method Details
-
compareImpl
This method does the actual comparison. It is called and then we modify the result if we are performing a reverse sort.- Parameters:
o1
- The first object to compareo2
- The second object to compare- Returns:
- -1, 0, 1 as defined by the compareTo(Object, Object) interface
- Throws:
ClassCastException
- if the object types are not supported by this implementation- See Also:
-
setComparisonType
public void setComparisonType(int type) Sets the comparison type.- Parameters:
type
- The comparison type.- Throws:
IllegalArgumentException
- if the type is negative or > typeNames.length- See Also:
-
setComparisonType
Sets the comparison type.- Parameters:
type
- The comparison type, contained within _typeNames- Throws:
IllegalArgumentException
- if the type is not found in _typeNames- See Also:
-
getTypeNames
Return the list of comparison type names.- Returns:
- an array of type names
-
getComparisonType
public int getComparisonType()Return the comparison type.- Returns:
- The comparison type in use
- See Also:
-
compare
Return the result by interrogating the implementation and applying a reverse sort if requred.- Specified by:
compare
in interfaceComparator<T>
- Parameters:
o1
- The first object to compareo2
- The second object to compare- Returns:
- -1, 0, 1 as defined by the compareTo(Object, Object) interface
- Throws:
ClassCastException
- if the object types are not supported by this implementation- See Also:
-