U - either TimeUnit or SIpublic final class MachineTime<U> extends Object implements TimeSpan<U>, Serializable
Represents a duration for machine times in decimal seconds with nanosecond precision.
Note: Other time units are NOT contained but can be used in construction of a machine time. Example:
MachineTime<TimeUnit> mt = MachineTime.of(1, TimeUnit.HOURS); System.out.println(mt.contains(TimeUnit.HOURS)); // false System.out.println(mt.getSeconds); // 3600L
TimeUnit.SECONDS,
TimeUnit.NANOSECONDS,
SI.SECONDS,
SI.NANOSECONDS,
Serialized FormTimeSpan.Item<U>| Modifier and Type | Field and Description |
|---|---|
static TimeMetric<TimeUnit,MachineTime<TimeUnit>> |
ON_POSIX_SCALE
Metric on the POSIX scale (without leap seconds).
|
static TimeMetric<TimeUnit,MachineTime<SI>> |
ON_UTC_SCALE
Metric on the UTC scale (inclusive leap seconds).
|
| Modifier and Type | Method and Description |
|---|---|
MachineTime<U> |
abs()
Converts this machine duration to its absolute amount.
|
<T extends TimePoint<? super U,T>> |
addTo(T time)
Adds this time span to given time point.
|
boolean |
contains(Object unit)
Queries if given time unit is part of this time span.
|
MachineTime<U> |
dividedBy(long divisor)
Divides this duration by given divisor using rounding
mode
HALF_UP. |
boolean |
equals(Object obj) |
int |
getFraction()
Yields the nanosecond fraction of this duration.
|
long |
getPartialAmount(Object unit)
Yields the partial amount associated with given time unit.
|
TimeScale |
getScale()
Yields the related time scale.
|
long |
getSeconds()
Yields the seconds of this duration.
|
List<TimeSpan.Item<U>> |
getTotalLength()
Yields all containted time span items with amount and unit in
the order from largest to smallest time units.
|
int |
hashCode() |
MachineTime<U> |
inverse()
Creates a copy with inversed sign.
|
boolean |
isEmpty()
Queries if this time span is empty.
|
boolean |
isNegative()
Queries if this time span is negative.
|
boolean |
isPositive()
Queries if this time span is positive.
|
MachineTime<U> |
minus(long amount,
U unit)
Subtracts given temporal amount from this machine time.
|
MachineTime<U> |
minus(MachineTime<U> duration)
Subtracts given temporal amount from this machine time.
|
MachineTime<U> |
multipliedBy(long factor)
Multiplies this duration with given factor.
|
static MachineTime<SI> |
of(long amount,
SI unit)
Creates a machine time duration on the UTC scale.
|
static MachineTime<TimeUnit> |
of(long amount,
TimeUnit unit)
Creates a machine time duration on the POSIX scale.
|
static MachineTime<TimeUnit> |
ofPosixSeconds(BigDecimal seconds)
Creates a machine time duration on the UTC scale.
|
static MachineTime<TimeUnit> |
ofPosixSeconds(double seconds)
Creates a machine time duration on the UTC scale.
|
static MachineTime<TimeUnit> |
ofPosixUnits(long seconds,
int fraction)
Creates a machine time duration on the POSIX scale.
|
static MachineTime<SI> |
ofSISeconds(BigDecimal seconds)
Creates a machine time duration on the UTC scale.
|
static MachineTime<SI> |
ofSISeconds(double seconds)
Creates a machine time duration on the UTC scale.
|
static MachineTime<SI> |
ofSIUnits(long seconds,
int fraction)
Creates a machine time duration on the UTC scale.
|
MachineTime<U> |
plus(long amount,
U unit)
Add given temporal amount to this machine time.
|
MachineTime<U> |
plus(MachineTime<U> duration)
Add given temporal amount to this machine time.
|
<T extends TimePoint<? super U,T>> |
subtractFrom(T time)
Subtracts this time span from given time point.
|
BigDecimal |
toBigDecimal()
Converts this machine time duration into a decimal number of
seconds.
|
String |
toString() |
public static final TimeMetric<TimeUnit,MachineTime<TimeUnit>> ON_POSIX_SCALE
public static final TimeMetric<TimeUnit,MachineTime<SI>> ON_UTC_SCALE
Metric on the UTC scale (inclusive leap seconds).
Time points before 1972 are not supported.
public static MachineTime<TimeUnit> of(long amount, TimeUnit unit)
Creates a machine time duration on the POSIX scale.
If there is a subsecond fraction then the result will be
normalized such that the nanosecond part is always in the range
0-999999999.
amount - of unitsunit - helps to interprete given amountArithmeticException - in case of numerical overflowpublic static MachineTime<SI> of(long amount, SI unit)
Creates a machine time duration on the UTC scale.
If there is a subsecond fraction then the result will be
normalized such that the nanosecond part is always in the range
0-999999999.
amount - of unitsunit - helps to interprete given amountpublic static MachineTime<TimeUnit> ofPosixUnits(long seconds, int fraction)
Creates a machine time duration on the POSIX scale.
If there is a subsecond fraction then the result will be
normalized such that the nanosecond part is always in the range
0-999999999.
seconds - POSIX-secondsfraction - nanosecond partArithmeticException - in case of numerical overflowpublic static MachineTime<SI> ofSIUnits(long seconds, int fraction)
Creates a machine time duration on the UTC scale.
If there is a subsecond fraction then the result will be
normalized such that the nanosecond part is always in the range
0-999999999.
seconds - SI-secondsfraction - nanosecond partArithmeticException - in case of numerical overflowpublic static MachineTime<TimeUnit> ofPosixSeconds(double seconds)
Creates a machine time duration on the UTC scale.
If there is a subsecond fraction then the result will be
normalized such that the nanosecond part is always in the range
0-999999999.
seconds - decimal SI-secondsArithmeticException - in case of numerical overflowIllegalArgumentException - if the argument is infinite or NaNpublic static MachineTime<TimeUnit> ofPosixSeconds(BigDecimal seconds)
Creates a machine time duration on the UTC scale.
If there is a subsecond fraction then the result will be
normalized such that the nanosecond part is always in the range
0-999999999.
seconds - decimal SI-secondsArithmeticException - in case of numerical overflowpublic static MachineTime<SI> ofSISeconds(double seconds)
Creates a machine time duration on the UTC scale.
If there is a subsecond fraction then the result will be
normalized such that the nanosecond part is always in the range
0-999999999.
seconds - decimal SI-secondsArithmeticException - in case of numerical overflowIllegalArgumentException - if the argument is infinite or NaNpublic static MachineTime<SI> ofSISeconds(BigDecimal seconds)
Creates a machine time duration on the UTC scale.
If there is a subsecond fraction then the result will be
normalized such that the nanosecond part is always in the range
0-999999999.
seconds - decimal SI-secondsArithmeticException - in case of numerical overflowpublic long getSeconds()
Yields the seconds of this duration.
public int getFraction()
Yields the nanosecond fraction of this duration.
0-999999999public TimeScale getScale()
Yields the related time scale.
TimeScale.POSIX or TimeScale.UTCpublic List<TimeSpan.Item<U>> getTotalLength()
TimeSpanYields all containted time span items with amount and unit in the order from largest to smallest time units.
getTotalLength in interface TimeSpan<U>public boolean contains(Object unit)
TimeSpanQueries if given time unit is part of this time span.
By default the implementation uses following expression:
for (Item<?> item : getTotalLength()) {
if (item.getUnit().equals(unit)) {
return (item.getAmount() > 0);
}
}
return false;
contains in interface TimeSpan<U>unit - time unit to be asked (optional)true if exists else falsegetPartialAmount(U)public long getPartialAmount(Object unit)
TimeSpanYields the partial amount associated with given time unit.
The method returns 0 if this time span does not contain
given time unit. In order to get the total length/amount of this
time span users have to evaluate the method TimeSpan.getTotalLength()
instead.
getPartialAmount in interface TimeSpan<U>unit - time unit (optional)>= 0)public boolean isNegative()
TimeSpanQueries if this time span is negative.
A negative time span relates to the subtraction of two time points where first one is after second one. The partial amounts of every time span are never negative. Hence this attribute is not associated with the partial amounts but only with the time span itself.
Note: An empty time span itself is never negative in agreement
with the mathematical relation (-1) * 0 = 0.
isNegative in interface TimeSpan<U>true if negative and not empty else falsepublic boolean isPositive()
TimeSpanQueries if this time span is positive.
A time span is positive if it is neither empty nor negative.
isPositive in interface TimeSpan<U>true if positive and not empty else falseTimeSpan.isEmpty(),
TimeSpan.isNegative()public boolean isEmpty()
TimeSpanQueries if this time span is empty.
Per definition an empty time span has no items with a partial
amount different from 0.
public MachineTime<U> plus(long amount, U unit)
Add given temporal amount to this machine time.
amount - the amount to be addedunit - the related time unitArithmeticException - in case of numerical overflowpublic MachineTime<U> plus(MachineTime<U> duration)
Add given temporal amount to this machine time.
duration - other machine time to be addedArithmeticException - in case of numerical overflowpublic MachineTime<U> minus(long amount, U unit)
Subtracts given temporal amount from this machine time.
amount - the amount to be subtractedunit - the related time unitArithmeticException - in case of numerical overflowpublic MachineTime<U> minus(MachineTime<U> duration)
Subtracts given temporal amount from this machine time.
duration - other machine time to be subtractedArithmeticException - in case of numerical overflowpublic MachineTime<U> abs()
Converts this machine duration to its absolute amount.
ArithmeticException - in case of numerical overflowpublic MachineTime<U> inverse()
Creates a copy with inversed sign.
ArithmeticException - in case of numerical overflowpublic MachineTime<U> multipliedBy(long factor)
Multiplies this duration with given factor.
factor - multiplicandpublic MachineTime<U> dividedBy(long divisor)
Divides this duration by given divisor using rounding
mode HALF_UP.
divisor - divisorRoundingMode.HALF_UPpublic <T extends TimePoint<? super U,T>> T addTo(T time)
TimeSpanAdds this time span to given time point.
Is equivalent to the expression time.plus(this). Due to better readability usage of the
TimePoint-method is recommended. Implementations are
required to document the used algorithm in detailed manner.
addTo in interface TimeSpan<U>T - generic type of time pointtime - reference time point to add this time span toTimeSpan.subtractFrom(TimePoint)public <T extends TimePoint<? super U,T>> T subtractFrom(T time)
TimeSpanSubtracts this time span from given time point.
Is equivalent to the expression time.minus(this). Due to better readability usage of the
TimePoint-method is recommended. Implementations are
required to document the used algorithm in detailed manner.
subtractFrom in interface TimeSpan<U>T - generic type of time pointtime - reference time point to subtract this time span fromTimeSpan.addTo(TimePoint)public BigDecimal toBigDecimal()
Converts this machine time duration into a decimal number of seconds.
Copyright © 2014. All rights reserved.