Class AbstractMetric<U extends ChronoUnit,P extends AbstractDuration<U>>
- Type Parameters:
U
- generic type of time unit (ChronoUnit
)P
- generic type of duration result
- All Implemented Interfaces:
Comparator<U>
,TimeMetric<U,P>
Represents a metric suitable for the default algorithm of Time4J.
If the starting time point is after the end time point then a
duration computed with this metric will be negative. In this case
the metric defined here will first toggle the time points to be
compared and then compare all elements in the order of ascending
precision. Elements which differ less than a full unit will cause
an amount of 0
in related duration item. Convertible units
will be consolidated in one step. Finally the representation of
the duration will be normalized such that small units will be
converted to larger units if possible.
This metric can be changed to a reversible one by calling reversible()
(third invariance in AbstractDuration
.
- Author:
- Meno Hochschild
- See Also:
AbstractDuration
-
Method Summary
Modifier and TypeMethodDescriptionbetween(T start, T end)
Computes the temporal distance between two time points.int
Compares time units by their length in descending order.TimeMetric<U,P>
Obtains a modified metric which has reversible characteristics.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Comparator
equals, reversed, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
-
Method Details
-
compare
Compares time units by their length in descending order.
- Specified by:
compare
in interfaceComparator<U extends ChronoUnit>
- Parameters:
u1
- first time unitu2
- second time unit- Returns:
- negative, zero or positive if u1 is greater, equal to or smaller than u2
-
between
Description copied from interface:TimeMetric
Computes the temporal distance between two time points.
Important note: This method might not work in Java 6 under some circumstances. In case of any problem users can use the equivalent method
until()
defined in the classTimePoint
.- Specified by:
between
in interfaceTimeMetric<U extends ChronoUnit,P extends AbstractDuration<U>>
- Type Parameters:
T
- generic type of time point- Parameters:
start
- first time pointend
- second time point- Returns:
- calculated time span between given time points, will be
negative if
start
is afterend
- See Also:
TimePoint.until(TimePoint, TimeMetric)
-
reversible
Description copied from interface:TimeMetric
Obtains a modified metric which has reversible characteristics.
Usually metrics are not reversible by default. The default implementation throws an
UnsupportedOperationException
. Overriding implementations should document the details of reversal characteristics.- Specified by:
reversible
in interfaceTimeMetric<U extends ChronoUnit,P extends AbstractDuration<U>>
- Returns:
- modified reversible time metric
-