Top Description Fields Constructors Methods
tech.units.indriya.quantity.time

public final Class TemporalQuantity

extends AbstractQuantity<Time>
Class Inheritance
Static Imports
tech.units.indriya.unit.Units.DAY, .Units.HOUR, .Units.MINUTE, .Units.SECOND

Class that represents TemporalUnit in Unit-API
Authors
Werner Keil, Filip van Laenen, Andi Huber
Since
1.0
Version
1.3, Jun 4, 2019

Field Summary

Modifier and TypeField and Description
private final Object
private transient TemporalAmount
private static final long
private final TemporalUnit
private final Number
Inherited from tech.units.indriya.AbstractQuantity:
NONEONE

Constructor Summary

AccessConstructor and Description
pack-priv
TemporalQuantity(Number
- value to be used
value
,
TemporalUnit
- time to be used
timeUnit
)

creates the TemporalQuantity using TemporalUnit and Number

Method Summary

Modifier and TypeMethod and Description
public ComparableQuantity<Time>
add(Quantity<Time>
the Quantity to be added.
that
)

Implements tech.units.indriya.ComparableQuantity.add.

Returns the sum of this Quantity with the one specified.

private ComparableQuantity<Time>
private ComparableQuantity<?>
private static <R extends Quantity<R>> Number
public ComparableQuantity<?>
divide(Quantity<?>
the Quantity divisor.
that
)

Implements tech.units.indriya.ComparableQuantity.divide.

Returns the quotient of this Quantity divided by the Quantity specified.

public ComparableQuantity<Time>
divide(Number
the Number divisor.
that
)

Implements tech.units.indriya.ComparableQuantity.divide.

Returns the quotient of this Quantity divided by the Number specified.

public boolean
equals(Object
the object to compare with.
obj
)

Overrides tech.units.indriya.AbstractQuantity.equals.

Compares this quantity against the specified object for strict equality (same unit and same amount).

public TemporalAmount

Returns:

the TemporalAmount
getTemporalAmount
()

Returns the TemporalAmount of this TemporalQuantity, which may involve rounding or truncation.

public TemporalUnit

Returns:

the TemporalUnit
getTemporalUnit
()

get to TemporalUnit

public Number
public int
hashCode()

Overrides tech.units.indriya.AbstractQuantity.hashCode.

Returns the hash code for this quantity.

public ComparableQuantity<Frequency>
inverse()

Implements tech.units.indriya.ComparableQuantity.inverse.

Returns a Quantity that is the multiplicative inverse of this Quantity, having reciprocal value and reciprocal unit as given by this.getUnit().inverse().

public ComparableQuantity<?>
multiply(Quantity<?>
the Quantity multiplicand.
that
)

Implements tech.units.indriya.ComparableQuantity.multiply.

Returns the product of this Quantity with the one specified.

public ComparableQuantity<Time>
multiply(Number
the Number multiplicand.
that
)

Implements tech.units.indriya.ComparableQuantity.multiply.

Returns the product of this Quantity with the Number value specified.

public Quantity<Time>
negate()

Implements javax.measure.Quantity.negate.

Returns a Quantity whose value is (-this.getValue()).

public static TemporalQuantity
of(Number number, TemporalUnit
- time to be used
timeUnit
)

creates the TemporalQuantity using TemporalUnit and Number

public static TemporalQuantity

Returns:

the TemporalQuantity converted be quantity in seconds.
of
(Quantity<Time>
- quantity to be used
quantity
)

Creates a TemporalQuantity based a Quantity<Time> converted to Units#SECOND.

private static <R extends Quantity<R>> Number
public ComparableQuantity<Time>
subtract(Quantity<Time>
the Quantity to be subtracted.
that
)

Implements tech.units.indriya.ComparableQuantity.subtract.

Returns the difference between this Quantity and the one specified.

public TemporalQuantity
to(TemporalUnit aTimeUnit)

public Quantity<Time>

Returns:

this class converted to Quantity
toQuantity
()

Converts the TemporalQuantity to Quantity<Time>

public String
toString()

Overrides tech.units.indriya.AbstractQuantity.toString.

Returns the String representation of this quantity.

public Unit<Time>

Returns:

the TemporalQuantity#getTemporalUnit() converted to Unit
toUnit
()

converts the TemporalUnit to Unit

private static Unit<Time>
toUnit(TemporalUnit timeUnit)

Inherited from tech.units.indriya.AbstractQuantity:
asTypecompareTodividegetScalegetUnithasFractionhasFractioninverseisEquivalentToisGreaterThanisGreaterThanOrEqualToisLessThanisLessThanOrEqualTomultiplyparseto

Field Detail

$lock1back to summary
private final Object $lock1
amountback to summary
private transient TemporalAmount amount
serialVersionUIDback to summary
private static final long serialVersionUID

Hides tech.units.indriya.AbstractQuantity.serialVersionUID.

timeUnitback to summary
private final TemporalUnit timeUnit
valueback to summary
private final Number value

Constructor Detail

TemporalQuantityback to summary
pack-priv TemporalQuantity(Number value, TemporalUnit timeUnit)

creates the TemporalQuantity using TemporalUnit and Number

Parameters
value:Number

- value to be used

timeUnit:TemporalUnit

- time to be used

Method Detail

addback to summary
public ComparableQuantity<Time> add(Quantity<Time> that)

Implements tech.units.indriya.ComparableQuantity.add.

Doc from javax.measure.Quantity.add.

Returns the sum of this Quantity with the one specified. The result shall be as if this quantity and the given addend were converted to system unit before to be added, and the result converted back to the unit of this quantity or any other compatible unit at implementation choice.

Parameters
that:Quantity<Time>

the Quantity to be added.

Returns:ComparableQuantity<Time>

this + addend.

Annotations
@Override
applyMultiplicativeNumberOperationback to summary
private ComparableQuantity<Time> applyMultiplicativeNumberOperation(Number that, BinaryOperator<Number> valueOperator)
applyMultiplicativeQuantityOperationback to summary
private ComparableQuantity<?> applyMultiplicativeQuantityOperation(Quantity<?> that, BinaryOperator<Number> valueOperator, BinaryOperator<Unit<?>> unitOperator)
convertedQuantityValueback to summary
private static <R extends Quantity<R>> Number convertedQuantityValue(Quantity<R> that, Unit<R> unit)
divideback to summary
public ComparableQuantity<?> divide(Quantity<?> that)

Implements tech.units.indriya.ComparableQuantity.divide.

Doc from javax.measure.Quantity.divide.

Returns the quotient of this Quantity divided by the Quantity specified. The result shall be as if this quantity and the given divisor were converted to system unit before to be divided, and the result converted back to the unit of this quantity or any other compatible unit at implementation choice.

Parameters
that:Quantity<?>

the Quantity divisor.

Returns:ComparableQuantity<?>

this / divisor.

Annotations
@Override
divideback to summary
public ComparableQuantity<Time> divide(Number that)

Implements tech.units.indriya.ComparableQuantity.divide.

Doc from javax.measure.Quantity.divide.

Returns the quotient of this Quantity divided by the Number specified. The result shall be as if this quantity was converted to system unit before to be divided, and the result converted back to the unit of this quantity or any other compatible unit at implementation choice.

Parameters
that:Number

the Number divisor.

Returns:ComparableQuantity<Time>

this / divisor.

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

Overrides tech.units.indriya.AbstractQuantity.equals.

Doc from tech.units.indriya.AbstractQuantity.equals.

Compares this quantity against the specified object for strict equality (same unit and same amount).

Similarly to the BigDecimal#equals method which consider 2.0 and 2.00 as different objects because of different internal scales, quantities such as Quantities.getQuantity(3.0, KILOGRAM) Quantities.getQuantity(3, KILOGRAM) and Quantities.getQuantity("3 kg") might not be considered equals because of possible differences in their implementations.

To compare quantities stated using different units or using different amount implementations the compareTo or isEquivalentTo methods should be used.

Parameters
obj:Object

the object to compare with.

Returns:boolean

this.getUnit.equals(obj.getUnit()) && this.getScale().equals(obj.getScale() && this.getValue().equals(obj.getValue())

Annotations
@Override
getTemporalAmountback to summary
public TemporalAmount getTemporalAmount()

Returns the TemporalAmount of this TemporalQuantity, which may involve rounding or truncation.

Returns:TemporalAmount

the TemporalAmount

Exceptions
ArithmeticException:
when the value of this TemporalQuantity cannot be converted to long
getTemporalUnitback to summary
public TemporalUnit getTemporalUnit()

get to TemporalUnit

Returns:TemporalUnit

the TemporalUnit

getValueback to summary
public Number getValue()

Implements abstract tech.units.indriya.AbstractQuantity.getValue.

Implements javax.measure.Quantity.getValue, tech.uom.lib.common.function.ValueSupplier.getValue.

get value expressed in Number

Returns:Number

the value

hashCodeback to summary
public int hashCode()

Overrides tech.units.indriya.AbstractQuantity.hashCode.

Doc from tech.units.indriya.AbstractQuantity.hashCode.

Returns the hash code for this quantity.

Returns:int

the hash code value.

Annotations
@Override
inverseback to summary
public ComparableQuantity<Frequency> inverse()

Implements tech.units.indriya.ComparableQuantity.inverse.

Doc from javax.measure.Quantity.inverse.

Returns a Quantity that is the multiplicative inverse of this Quantity, having reciprocal value and reciprocal unit as given by this.getUnit().inverse().

Returns:ComparableQuantity<Frequency>

reciprocal Quantity

Annotations
@Override
multiplyback to summary
public ComparableQuantity<?> multiply(Quantity<?> that)

Implements tech.units.indriya.ComparableQuantity.multiply.

Doc from javax.measure.Quantity.multiply.

Returns the product of this Quantity with the one specified. The result shall be as if this quantity and the given multiplicand were converted to system unit before to be multiplied, and the result converted back to the unit of this quantity or any other compatible unit at implementation choice.

Parameters
that:Quantity<?>

the Quantity multiplicand.

Returns:ComparableQuantity<?>

this * multiplicand.

Annotations
@Override
multiplyback to summary
public ComparableQuantity<Time> multiply(Number that)

Implements tech.units.indriya.ComparableQuantity.multiply.

Doc from javax.measure.Quantity.multiply.

Returns the product of this Quantity with the Number value specified. The result shall be as if this quantity was converted to system unit before to be multiplied, and the result converted back to the unit of this quantity or any other compatible unit at implementation choice.

Parameters
that:Number

the Number multiplicand.

Returns:ComparableQuantity<Time>

this * multiplicand.

Annotations
@Override
negateback to summary
public Quantity<Time> negate()

Implements javax.measure.Quantity.negate.

Doc from javax.measure.Quantity.negate.

Returns a Quantity whose value is (-this.getValue()).

Returns:Quantity<Time>

-this.

Annotations
@Override
Since
1.0.2
ofback to summary
public static TemporalQuantity of(Number number, TemporalUnit timeUnit)

creates the TemporalQuantity using TemporalUnit and Number

Parameters
timeUnit:TemporalUnit

- time to be used

ofback to summary
public static TemporalQuantity of(Quantity<Time> quantity)

Creates a TemporalQuantity based a Quantity<Time> converted to Units#SECOND.

Parameters
quantity:Quantity<Time>

- quantity to be used

Returns:TemporalQuantity

the TemporalQuantity converted be quantity in seconds.

quantityValueback to summary
private static <R extends Quantity<R>> Number quantityValue(Quantity<R> that)
subtractback to summary
public ComparableQuantity<Time> subtract(Quantity<Time> that)

Implements tech.units.indriya.ComparableQuantity.subtract.

Doc from javax.measure.Quantity.subtract.

Returns the difference between this Quantity and the one specified. The result shall be as if this quantity and the given subtrahend were converted to system unit before to be subtracted, and the result converted back to the unit of this quantity or any other compatible unit at implementation choice.

Parameters
that:Quantity<Time>

the Quantity to be subtracted.

Returns:ComparableQuantity<Time>

this - subtrahend.

Annotations
@Override
toback to summary
public TemporalQuantity to(TemporalUnit aTimeUnit)
toQuantityback to summary
public Quantity<Time> toQuantity()

Converts the TemporalQuantity to Quantity<Time>

Returns:Quantity<Time>

this class converted to Quantity

toStringback to summary
public String toString()

Overrides tech.units.indriya.AbstractQuantity.toString.

Doc from tech.units.indriya.AbstractQuantity.toString.

Returns the String representation of this quantity. The string produced for a given quantity is always the same; it is not affected by locale. This means that it can be used as a canonical string representation for exchanging quantity, or as a key for a Hashtable, etc. Locale-sensitive quantity formatting and parsing is handled by the QuantityFormat implementations and its subclasses.

Returns:String

SimpleQuantityFormat.getInstance().format(this)

Annotations
@Override
toUnitback to summary
public Unit<Time> toUnit()

converts the TemporalUnit to Unit

Returns:Unit<Time>

the TemporalQuantity#getTemporalUnit() converted to Unit

toUnitback to summary
private static Unit<Time> toUnit(TemporalUnit timeUnit)