U - generic type of time unit (ChronoUnit)P - generic type of duration resultpublic abstract class AbstractMetric<U extends ChronoUnit,P extends AbstractDuration<U>> extends Object implements TimeMetric<U,P>, Comparator<U>
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.
AbstractDuration| Modifier | Constructor and Description |
|---|---|
protected |
AbstractMetric(boolean normalizing,
Set<U> units)
Creates a new default metric with given set of time units.
|
protected |
AbstractMetric(boolean normalizing,
U... units)
Creates a new default metric with given array of time units.
|
| Modifier and Type | Method and Description |
|---|---|
<T extends TimePoint<? super U,T>> |
between(T start,
T end)
Computes the temporal distance between two time points.
|
int |
compare(U u1,
U u2)
Compares time units by their length in descending order.
|
protected abstract P |
createEmptyTimeSpan()
Creates an empty time span.
|
protected abstract P |
createTimeSpan(List<TimeSpan.Item<U>> items,
boolean negative)
Creates a time span with the given units and amounts.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitequalsprotected AbstractMetric(boolean normalizing,
U... units)
Creates a new default metric with given array of time units.
The given time units can be in any arbitrary order, but internally the will be automatically sorted by their default estimated length.
normalizing - Is normalizing required that is shall amounts
in small units be converted to bigger units?units - time units to be used for calculating time spanIllegalArgumentException - if any time unit is given more than
once or if there is no time unit at allprotected AbstractMetric(boolean normalizing,
Set<U> units)
Creates a new default metric with given set of time units.
The given time units can be in any arbitrary order, but internally the will be automatically sorted by their default estimated length.
normalizing - Is normalizing required that is shall amounts
in small units be converted to bigger units?units - time units to be used for calculating time spanIllegalArgumentException - if there is not time unit at allpublic int compare(U u1, U u2)
Compares time units by their length in descending order.
compare in interface Comparator<U extends ChronoUnit>u1 - first time unitu2 - second time unitpublic <T extends TimePoint<? super U,T>> P between(T start, T end)
TimeMetricComputes the temporal distance between two time points.
between in interface TimeMetric<U extends ChronoUnit,P extends AbstractDuration<U>>T - generic type of time pointstart - first time pointend - second time pointstart is after endprotected abstract P createEmptyTimeSpan()
Creates an empty time span.
TimeSpan.isEmpty()protected abstract P createTimeSpan(List<TimeSpan.Item<U>> items, boolean negative)
Creates a time span with the given units and amounts.
items - elements of time spannegative - sign of time spanCopyright © 2014–2015. All rights reserved.