Package tech.units.indriya.quantity.time
Class TemporalQuantity
- java.lang.Object
-
- tech.units.indriya.AbstractQuantity<javax.measure.quantity.Time>
-
- tech.units.indriya.quantity.time.TemporalQuantity
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<javax.measure.Quantity<javax.measure.quantity.Time>>
,javax.measure.Quantity<javax.measure.quantity.Time>
,ComparableQuantity<javax.measure.quantity.Time>
,tech.uom.lib.common.function.QuantityConverter<javax.measure.quantity.Time>
,tech.uom.lib.common.function.UnitSupplier<javax.measure.quantity.Time>
,tech.uom.lib.common.function.ValueSupplier<java.lang.Number>
public final class TemporalQuantity extends AbstractQuantity<javax.measure.quantity.Time>
Class that representsTemporalUnit
in Unit-API- Since:
- 1.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class tech.units.indriya.AbstractQuantity
AbstractQuantity.Equalizer
-
-
Field Summary
Fields Modifier and Type Field Description private java.time.temporal.TemporalAmount
amount
private static long
serialVersionUID
private java.time.temporal.TemporalUnit
timeUnit
private java.lang.Integer
value
-
Fields inherited from class tech.units.indriya.AbstractQuantity
NONE, ONE
-
-
Constructor Summary
Constructors Constructor Description TemporalQuantity(java.lang.Integer value, java.time.temporal.TemporalUnit timeUnit)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ComparableQuantity<javax.measure.quantity.Time>
add(javax.measure.Quantity<javax.measure.quantity.Time> that)
java.math.BigDecimal
decimalValue(javax.measure.Unit<javax.measure.quantity.Time> unit)
ComparableQuantity<javax.measure.quantity.Time>
divide(java.lang.Number that)
ComparableQuantity<?>
divide(javax.measure.Quantity<?> that)
double
doubleValue(javax.measure.Unit<javax.measure.quantity.Time> unit)
boolean
equals(java.lang.Object obj)
Compares this quantity against the specified object for strict equality (same unit and same amount).java.time.temporal.TemporalAmount
getTemporalAmount()
get toTemporalAmount
java.time.temporal.TemporalUnit
getTemporalUnit()
get toTemporalUnit
java.lang.Integer
getValue()
get value expressed inInteger
int
hashCode()
Returns the hash code for this quantity.ComparableQuantity<javax.measure.quantity.Frequency>
inverse()
boolean
isBig()
ComparableQuantity<javax.measure.quantity.Time>
multiply(java.lang.Number multiplier)
ComparableQuantity<?>
multiply(javax.measure.Quantity<?> multiplier)
static TemporalQuantity
of(java.lang.Integer number, java.time.temporal.TemporalUnit timeUnit)
static TemporalQuantity
of(javax.measure.Quantity<javax.measure.quantity.Time> quantity)
ComparableQuantity<javax.measure.quantity.Time>
subtract(javax.measure.Quantity<javax.measure.quantity.Time> that)
TemporalQuantity
to(java.time.temporal.TemporalUnit timeUnit)
javax.measure.Quantity<javax.measure.quantity.Time>
toQuantity()
Converts theTemporalQuantity
toQuantity
java.lang.String
toString()
Returns theString
representation of this quantity.javax.measure.Unit<javax.measure.quantity.Time>
toUnit()
converts theTemporalUnit
toUnit
private static javax.measure.Unit<javax.measure.quantity.Time>
toUnit(java.time.temporal.TemporalUnit timeUnit)
-
Methods inherited from class tech.units.indriya.AbstractQuantity
asType, compareTo, divide, equals, floatValue, getUnit, hasFraction, hasFraction, intValue, inverse, isEquivalentOf, isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo, longValue, multiply, parse, to
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
timeUnit
private final java.time.temporal.TemporalUnit timeUnit
-
value
private final java.lang.Integer value
-
amount
private final java.time.temporal.TemporalAmount amount
-
-
Method Detail
-
of
public static TemporalQuantity of(java.lang.Integer number, java.time.temporal.TemporalUnit timeUnit)
- Parameters:
value
- - value to be usedtimeUnit
- - time to be used
-
of
public static TemporalQuantity of(javax.measure.Quantity<javax.measure.quantity.Time> quantity)
- Parameters:
quantity
- - quantity to be used- Returns:
- the
TemporalQuantity
converted be quantity in seconds.
-
getTemporalAmount
public java.time.temporal.TemporalAmount getTemporalAmount()
get toTemporalAmount
- Returns:
- the TemporalAmount
-
getTemporalUnit
public java.time.temporal.TemporalUnit getTemporalUnit()
get toTemporalUnit
- Returns:
- the TemporalUnit
-
getValue
public java.lang.Integer getValue()
get value expressed inInteger
- Specified by:
getValue
in interfacejavax.measure.Quantity<javax.measure.quantity.Time>
- Specified by:
getValue
in interfacetech.uom.lib.common.function.ValueSupplier<java.lang.Number>
- Specified by:
getValue
in classAbstractQuantity<javax.measure.quantity.Time>
- Returns:
- the value
-
toUnit
public javax.measure.Unit<javax.measure.quantity.Time> toUnit()
converts theTemporalUnit
toUnit
- Returns:
- the
getTemporalUnit()
converted to Unit
-
toQuantity
public javax.measure.Quantity<javax.measure.quantity.Time> toQuantity()
Converts theTemporalQuantity
toQuantity
- Returns:
- this class converted to Quantity
-
to
public TemporalQuantity to(java.time.temporal.TemporalUnit timeUnit)
-
toUnit
private static javax.measure.Unit<javax.measure.quantity.Time> toUnit(java.time.temporal.TemporalUnit timeUnit)
-
hashCode
public int hashCode()
Description copied from class:AbstractQuantity
Returns the hash code for this quantity.- Overrides:
hashCode
in classAbstractQuantity<javax.measure.quantity.Time>
- Returns:
- the hash code value.
-
equals
public boolean equals(java.lang.Object obj)
Description copied from class:AbstractQuantity
Compares this quantity against the specified object for strict equality (same unit and same amount).Similarly to the
BigDecimal.equals(java.lang.Object)
method which consider 2.0 and 2.00 as different objects because of different internal scales, quantities such asQuantities.getQuantity(3.0, KILOGRAM)
Quantities.getQuantity(3, KILOGRAM)
andQuantities.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
orequals(Quantity, epsilon, epsilonUnit)
methods should be used.- Overrides:
equals
in classAbstractQuantity<javax.measure.quantity.Time>
- Parameters:
obj
- the object to compare with.- Returns:
this.getUnit.equals(obj.getUnit()) && this.getValue().equals(obj.getValue())
-
toString
public java.lang.String toString()
Description copied from class:AbstractQuantity
Returns theString
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 theQuantityFormat
implementations and its subclasses.- Overrides:
toString
in classAbstractQuantity<javax.measure.quantity.Time>
- Returns:
UnitFormat.getInternational().format(this)
-
add
public ComparableQuantity<javax.measure.quantity.Time> add(javax.measure.Quantity<javax.measure.quantity.Time> that)
- See Also:
Quantity.add(Quantity)
-
subtract
public ComparableQuantity<javax.measure.quantity.Time> subtract(javax.measure.Quantity<javax.measure.quantity.Time> that)
- See Also:
Quantity.subtract(Quantity)
-
divide
public ComparableQuantity<?> divide(javax.measure.Quantity<?> that)
- See Also:
Quantity.divide(Quantity)
-
divide
public ComparableQuantity<javax.measure.quantity.Time> divide(java.lang.Number that)
- See Also:
Quantity.divide(Number)
-
multiply
public ComparableQuantity<?> multiply(javax.measure.Quantity<?> multiplier)
- See Also:
Quantity.multiply(Quantity)
-
multiply
public ComparableQuantity<javax.measure.quantity.Time> multiply(java.lang.Number multiplier)
- See Also:
Quantity.multiply(Number)
-
inverse
public ComparableQuantity<javax.measure.quantity.Frequency> inverse()
- See Also:
Quantity.inverse()
-
isBig
public boolean isBig()
- Specified by:
isBig
in classAbstractQuantity<javax.measure.quantity.Time>
-
decimalValue
public java.math.BigDecimal decimalValue(javax.measure.Unit<javax.measure.quantity.Time> unit) throws java.lang.ArithmeticException
- Specified by:
decimalValue
in classAbstractQuantity<javax.measure.quantity.Time>
- Throws:
java.lang.ArithmeticException
-
doubleValue
public double doubleValue(javax.measure.Unit<javax.measure.quantity.Time> unit) throws java.lang.ArithmeticException
- Specified by:
doubleValue
in classAbstractQuantity<javax.measure.quantity.Time>
- Throws:
java.lang.ArithmeticException
-
-