U - either TimeUnit or SIpublic final class MachineTime<U> extends Object implements RealTime<U>, Comparable<MachineTime<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 Form| Modifier and Type | Class and Description |
|---|---|
static class |
MachineTime.Formatter
Non-localized and user-defined format for machine-time-durations based on a
pattern containing some standard symbols and literals.
|
TimeSpan.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) |
int |
compareTo(MachineTime<U> other)
Method of the
Comparable-interface. |
boolean |
contains(Object unit) |
MachineTime<U> |
dividedBy(long divisor)
Deprecated.
Use
dividedBy(long, RoundingMode.HALF_UP instead |
MachineTime<U> |
dividedBy(long divisor,
RoundingMode roundingMode)
Divides this duration by given divisor using given rounding mode.
|
boolean |
equals(Object obj) |
static MachineTime<TimeUnit> |
from(Duration threeten)
Converts given JSR-310-duration to a machine time.
|
int |
getFraction() |
long |
getPartialAmount(Object unit) |
TimeScale |
getScale()
Yields the related time scale.
|
long |
getSeconds() |
List<TimeSpan.Item<U>> |
getTotalLength() |
int |
hashCode() |
MachineTime<U> |
inverse()
Creates a copy with inversed sign.
|
boolean |
isEmpty() |
boolean |
isLongerThan(MachineTime<U> other)
Compares the absolute lengths and is equivalent to
abs().compareTo(other.abs()) > 0. |
boolean |
isNegative() |
boolean |
isPositive() |
boolean |
isShorterThan(MachineTime<U> other)
Compares the absolute lengths and is equivalent to
abs().compareTo(other.abs()) < 0. |
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(double factor)
Multiplies this duration with given decimal factor.
|
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 POSIX scale.
|
static MachineTime<TimeUnit> |
ofPosixSeconds(double seconds)
Creates a machine time duration on the POSIX 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) |
BigDecimal |
toBigDecimal()
Converts this machine time duration into a decimal number of seconds.
|
String |
toString()
Returns a format in technical notation including the name of the underlying time scale.
|
Duration |
toTemporalAmount()
Converts this machine time to its JSR-310-equivalent.
|
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.
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.
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.
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.
seconds - SI-secondsfraction - nanosecond partArithmeticException - in case of numerical overflowpublic static MachineTime<TimeUnit> ofPosixSeconds(double seconds)
Creates a machine time duration on the POSIX scale.
seconds - decimal POSIX-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 POSIX scale.
seconds - decimal POSIX-secondsArithmeticException - in case of numerical overflowpublic static MachineTime<SI> ofSISeconds(double seconds)
Creates a machine time duration on the UTC scale.
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.
seconds - decimal SI-secondsArithmeticException - in case of numerical overflowpublic long getSeconds()
getSeconds in interface RealTime<U>public int getFraction()
getFraction in interface RealTime<U>public TimeScale getScale()
Yields the related time scale.
TimeScale.POSIX or TimeScale.UTCpublic List<TimeSpan.Item<U>> getTotalLength()
getTotalLength in interface TimeSpan<U>public long getPartialAmount(Object unit)
getPartialAmount in interface TimeSpan<U>public boolean isNegative()
isNegative in interface TimeSpan<U>public boolean isPositive()
isPositive in interface TimeSpan<U>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> multipliedBy(double factor)
Multiplies this duration with given decimal factor.
If more rounding control is needed then users might consider the alternatives
multipliedBy(long) and dividedBy(long, RoundingMode).
factor - multiplicandIllegalArgumentException - if given factor is not a finite number@Deprecated public MachineTime<U> dividedBy(long divisor)
dividedBy(long, RoundingMode.HALF_UP insteadDivides this duration by given divisor using rounding
mode HALF_UP.
divisor - divisorRoundingMode.HALF_UPpublic MachineTime<U> dividedBy(long divisor, RoundingMode roundingMode)
Divides this duration by given divisor using given rounding mode.
divisor - divisorroundingMode - rounding mode to be used in divisionpublic <T extends TimePoint<? super U,T>> T subtractFrom(T time)
subtractFrom in interface TimeSpan<U>public boolean isShorterThan(MachineTime<U> other)
Compares the absolute lengths and is equivalent to abs().compareTo(other.abs()) < 0.
other - another machine time to be compared withcompareTo(MachineTime),
isLongerThan(MachineTime)public boolean isLongerThan(MachineTime<U> other)
Compares the absolute lengths and is equivalent to abs().compareTo(other.abs()) > 0.
other - another machine time to be compared withcompareTo(MachineTime),
isShorterThan(MachineTime)public int compareTo(MachineTime<U> other)
Method of the Comparable-interface.
compareTo in interface Comparable<MachineTime<U>>other - another machine time to be compared withClassCastException - if this and the other machine time have different time scalesisShorterThan(MachineTime),
isLongerThan(MachineTime)public String toString()
Returns a format in technical notation including the name of the underlying time scale.
public BigDecimal toBigDecimal()
Converts this machine time duration into a decimal number of seconds.
public Duration toTemporalAmount()
Converts this machine time to its JSR-310-equivalent.
IllegalStateException - if this instance is not based on java.util.concurrent.TimeUnitfrom(java.time.Duration)public static MachineTime<TimeUnit> from(Duration threeten)
Converts given JSR-310-duration to a machine time.
threeten - duration defined in seconds and nanoseconds (JSR-310-API)toTemporalAmount()Copyright © 2014–2018. All rights reserved.