Class DateTimeComparator
- All Implemented Interfaces:
Serializable,Comparator<Object>
Dates may be specified using any object recognised by the
ConverterManager class.
The default objects recognised by the comparator are:
- ReadableInstant
- String
- Calendar
- Date
- Long (milliseconds)
- null (now)
DateTimeComparator is thread-safe and immutable.
- Since:
- 1.0
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final DateTimeComparatorSingleton instanceprivate static final DateTimeComparatorSingleton instanceprivate final DateTimeFieldTypeThe lower limit of fields to compare, null if no limitprivate final DateTimeFieldTypeThe upper limit of fields to compare, null if no limitprivate static final longSerialization lockprivate static final DateTimeComparatorSingleton instance -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedDateTimeComparator(DateTimeFieldType lowerLimit, DateTimeFieldType upperLimit) Restricted constructor. -
Method Summary
Modifier and TypeMethodDescriptionintCompare two objects against only the range of date time fields as specified in the constructor.booleanCompares this comparator to another.static DateTimeComparatorReturns a comparator that only considers date fields.static DateTimeComparatorReturns a DateTimeComparator the compares the entire date time value.static DateTimeComparatorgetInstance(DateTimeFieldType lowerLimit) Returns a DateTimeComparator with a lower limit only.static DateTimeComparatorgetInstance(DateTimeFieldType lowerLimit, DateTimeFieldType upperLimit) Returns a DateTimeComparator with a lower and upper limit.Gets the field type that represents the lower limit of comparison.static DateTimeComparatorReturns a comparator that only considers time fields.Gets the field type that represents the upper limit of comparison.inthashCode()Gets a suitable hashcode.private ObjectSupport serialization singletons.toString()Gets a debugging string.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Comparator
reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Field Details
-
serialVersionUID
private static final long serialVersionUIDSerialization lock- See Also:
-
ALL_INSTANCE
Singleton instance -
DATE_INSTANCE
Singleton instance -
TIME_INSTANCE
Singleton instance -
iLowerLimit
The lower limit of fields to compare, null if no limit -
iUpperLimit
The upper limit of fields to compare, null if no limit
-
-
Constructor Details
-
DateTimeComparator
Restricted constructor.- Parameters:
lowerLimit- the lower field limit, null means no limitupperLimit- the upper field limit, null means no limit
-
-
Method Details
-
getInstance
Returns a DateTimeComparator the compares the entire date time value.- Returns:
- a comparator over all fields
-
getInstance
Returns a DateTimeComparator with a lower limit only. Fields of a magnitude less than the lower limit are excluded from comparisons.The time-zone is considered when using this comparator. The input millis are truncated using the time-zone of that input value. Thus, two inputs with different time-zones will typically not be equal
- Parameters:
lowerLimit- inclusive lower limit for fields to be compared, null means no limit- Returns:
- a comparator over all fields above the lower limit
-
getInstance
public static DateTimeComparator getInstance(DateTimeFieldType lowerLimit, DateTimeFieldType upperLimit) Returns a DateTimeComparator with a lower and upper limit. Fields of a magnitude less than the lower limit are excluded from comparisons. Fields of a magnitude greater than or equal to the upper limit are also excluded from comparisons. Either limit may be specified as null, which indicates an unbounded limit.The time-zone is considered when using this comparator unless both limits are null. The input millis are rounded/truncated using the time-zone of that input value. Thus, two inputs with different time-zones will typically not be equal
- Parameters:
lowerLimit- inclusive lower limit for fields to be compared, null means no limitupperLimit- exclusive upper limit for fields to be compared, null means no limit- Returns:
- a comparator over all fields between the limits
-
getDateOnlyInstance
Returns a comparator that only considers date fields. Time of day is ignored.The time-zone is considered when using this comparator. The input millis are rounded down to the start of the day in the time-zone of that input value. Thus, two inputs with different time-zones will typically not be equal
- Returns:
- a comparator over all date fields
-
getTimeOnlyInstance
Returns a comparator that only considers time fields. Date is ignored.The time-zone is considered when using this comparator. The input millis are truncated to be within the day in the time-zone of that input value. Thus, two inputs with different time-zones will typically not be equal
- Returns:
- a comparator over all time fields
-
getLowerLimit
Gets the field type that represents the lower limit of comparison.- Returns:
- the field type, null if no upper limit
-
getUpperLimit
Gets the field type that represents the upper limit of comparison.- Returns:
- the field type, null if no upper limit
-
compare
Compare two objects against only the range of date time fields as specified in the constructor.- Specified by:
comparein interfaceComparator<Object>- Parameters:
lhsObj- the first object, logically on the left of a < comparison, null means nowrhsObj- the second object, logically on the right of a < comparison, null means now- Returns:
- zero if order does not matter, negative value if lhsObj < rhsObj, positive value otherwise.
- Throws:
IllegalArgumentException- if either argument is not supported
-
readResolve
Support serialization singletons.- Returns:
- the resolved singleton instance
-
equals
Compares this comparator to another.- Specified by:
equalsin interfaceComparator<Object>- Overrides:
equalsin classObject- Parameters:
object- the object to compare to- Returns:
- true if equal
-
hashCode
public int hashCode()Gets a suitable hashcode. -
toString
Gets a debugging string.
-