Package tech.units.indriya.quantity
Class NumberQuantity<Q extends javax.measure.Quantity<Q>>
- java.lang.Object
-
- tech.units.indriya.AbstractQuantity<Q>
-
- tech.units.indriya.quantity.NumberQuantity<Q>
-
- Type Parameters:
Q- The type of the quantity.
- All Implemented Interfaces:
java.io.Serializable,java.lang.Comparable<javax.measure.Quantity<Q>>,javax.measure.Quantity<Q>,ComparableQuantity<Q>,tech.uom.lib.common.function.QuantityConverter<Q>,tech.uom.lib.common.function.UnitSupplier<Q>,tech.uom.lib.common.function.ValueSupplier<java.lang.Number>
public class NumberQuantity<Q extends javax.measure.Quantity<Q>> extends AbstractQuantity<Q> implements java.io.Serializable
An amount of quantity, implementation ofComparableQuantitythat keepNumberas possible otherwise converts toDecimalQuantity, this object is immutable.- Since:
- 1.0
- Version:
- 1.0.1, $Date: 2017-05-28 $
- See Also:
AbstractQuantity,Quantity,ComparableQuantity, 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 booleanisBigIndicates if this quantity is big.private static longserialVersionUIDprivate java.lang.Numbervalue-
Fields inherited from class tech.units.indriya.AbstractQuantity
NONE, ONE
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedNumberQuantity(java.lang.Number number, javax.measure.Unit<Q> unit)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ComparableQuantity<Q>add(javax.measure.Quantity<Q> that)java.math.BigDecimaldecimalValue(javax.measure.Unit<Q> unit)ComparableQuantity<Q>divide(java.lang.Number that)ComparableQuantity<?>divide(javax.measure.Quantity<?> that)doubledoubleValue(javax.measure.Unit<Q> unit)booleanequals(java.lang.Object obj)Compares this quantity against the specified object for strict equality (same unit and same amount).java.lang.NumbergetValue()Returns the numeric value of the quantity.ComparableQuantity<Q>inverse()booleanisBig()Indicates if this measured amount is a big number, i.E.ComparableQuantity<Q>multiply(java.lang.Number that)ComparableQuantity<?>multiply(javax.measure.Quantity<?> that)static <Q extends javax.measure.Quantity<Q>>
AbstractQuantity<Q>of(byte value, javax.measure.Unit<Q> unit)Returns the scalar quantity for the specifiedbytestated in the specified unit.static <Q extends javax.measure.Quantity<Q>>
AbstractQuantity<Q>of(double doubleValue, javax.measure.Unit<Q> unit)Returns the scalar quantity for the specifieddoublestated in the specified unit.static <Q extends javax.measure.Quantity<Q>>
AbstractQuantity<Q>of(float floatValue, javax.measure.Unit<Q> unit)Returns the scalar quantity for the specifiedfloatstated in the specified unit.static <Q extends javax.measure.Quantity<Q>>
AbstractQuantity<Q>of(int intValue, javax.measure.Unit<Q> unit)Returns the scalar quantity for the specifiedintstated in the specified unit.static <Q extends javax.measure.Quantity<Q>>
AbstractQuantity<Q>of(long longValue, javax.measure.Unit<Q> unit)Returns the scalar quantity for the specifiedlongstated in the specified unit.static <Q extends javax.measure.Quantity<Q>>
AbstractQuantity<Q>of(short value, javax.measure.Unit<Q> unit)Returns the scalar quantity for the specifiedshortstated in the specified unit.ComparableQuantity<Q>subtract(javax.measure.Quantity<Q> that)private DecimalQuantity<Q>toDecimalQuantity()-
Methods inherited from class tech.units.indriya.AbstractQuantity
asType, compareTo, divide, equals, floatValue, getUnit, hasFraction, hasFraction, hashCode, intValue, inverse, isEquivalentOf, isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo, longValue, multiply, parse, to, toString
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
value
private final java.lang.Number value
-
isBig
private final boolean isBig
Indicates if this quantity is big.
-
-
Constructor Detail
-
NumberQuantity
protected NumberQuantity(java.lang.Number number, javax.measure.Unit<Q> unit)
-
-
Method Detail
-
doubleValue
public double doubleValue(javax.measure.Unit<Q> unit)
- Specified by:
doubleValuein classAbstractQuantity<Q extends javax.measure.Quantity<Q>>
-
getValue
public java.lang.Number getValue()
Description copied from class:AbstractQuantityReturns the numeric value of the quantity.- Specified by:
getValuein interfacejavax.measure.Quantity<Q extends javax.measure.Quantity<Q>>- Specified by:
getValuein interfacetech.uom.lib.common.function.ValueSupplier<Q extends javax.measure.Quantity<Q>>- Specified by:
getValuein classAbstractQuantity<Q extends javax.measure.Quantity<Q>>- Returns:
- the quantity value.
-
isBig
public boolean isBig()
Indicates if this measured amount is a big number, i.E. BigDecimal or BigInteger. In all other cases this would be false.- Specified by:
isBigin classAbstractQuantity<Q extends javax.measure.Quantity<Q>>- Returns:
trueif this quantity is big;falseotherwise.
-
add
public ComparableQuantity<Q> add(javax.measure.Quantity<Q> that)
-
multiply
public ComparableQuantity<?> multiply(javax.measure.Quantity<?> that)
-
multiply
public ComparableQuantity<Q> multiply(java.lang.Number that)
-
divide
public ComparableQuantity<?> divide(javax.measure.Quantity<?> that)
-
divide
public ComparableQuantity<Q> divide(java.lang.Number that)
-
inverse
public ComparableQuantity<Q> inverse()
-
decimalValue
public java.math.BigDecimal decimalValue(javax.measure.Unit<Q> unit) throws java.lang.ArithmeticException
- Specified by:
decimalValuein classAbstractQuantity<Q extends javax.measure.Quantity<Q>>- Throws:
java.lang.ArithmeticException
-
subtract
public ComparableQuantity<Q> subtract(javax.measure.Quantity<Q> that)
-
toDecimalQuantity
private DecimalQuantity<Q> toDecimalQuantity()
-
of
public static <Q extends javax.measure.Quantity<Q>> AbstractQuantity<Q> of(long longValue, javax.measure.Unit<Q> unit)
Returns the scalar quantity for the specifiedlongstated in the specified unit.- Parameters:
longValue- the quantity value.unit- the measurement unit.- Returns:
- the corresponding
intquantity.
-
of
public static <Q extends javax.measure.Quantity<Q>> AbstractQuantity<Q> of(int intValue, javax.measure.Unit<Q> unit)
Returns the scalar quantity for the specifiedintstated in the specified unit.- Parameters:
intValue- the quantity value.unit- the measurement unit.- Returns:
- the corresponding
intquantity.
-
of
public static <Q extends javax.measure.Quantity<Q>> AbstractQuantity<Q> of(short value, javax.measure.Unit<Q> unit)
Returns the scalar quantity for the specifiedshortstated in the specified unit.- Parameters:
value- the quantity value.unit- the measurement unit.- Returns:
- the corresponding
shortquantity.
-
of
public static <Q extends javax.measure.Quantity<Q>> AbstractQuantity<Q> of(byte value, javax.measure.Unit<Q> unit)
Returns the scalar quantity for the specifiedbytestated in the specified unit.- Parameters:
value- the quantity value.unit- the measurement unit.- Returns:
- the corresponding
bytequantity.
-
of
public static <Q extends javax.measure.Quantity<Q>> AbstractQuantity<Q> of(float floatValue, javax.measure.Unit<Q> unit)
Returns the scalar quantity for the specifiedfloatstated in the specified unit.- Parameters:
floatValue- the measurement value.unit- the measurement unit.- Returns:
- the corresponding
floatquantity.
-
of
public static <Q extends javax.measure.Quantity<Q>> AbstractQuantity<Q> of(double doubleValue, javax.measure.Unit<Q> unit)
Returns the scalar quantity for the specifieddoublestated in the specified unit.- Parameters:
doubleValue- the measurement value.unit- the measurement unit.- Returns:
- the corresponding
doublequantity.
-
equals
public boolean equals(java.lang.Object obj)
Description copied from class:AbstractQuantityCompares 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
compareToorequals(Quantity, epsilon, epsilonUnit)methods should be used.- Overrides:
equalsin classAbstractQuantity<Q extends javax.measure.Quantity<Q>>- Parameters:
obj- the object to compare with.- Returns:
this.getUnit.equals(obj.getUnit()) && this.getValue().equals(obj.getValue())
-
-