Q - The type of the quantity.public class NumberQuantity<Q extends javax.measure.Quantity<Q>> extends AbstractQuantity<Q> implements Serializable
ComparableQuantity that keep Number as possible otherwise converts to
DecimalQuantity, this object is immutable.AbstractQuantity,
Quantity,
ComparableQuantity,
Serialized FormAbstractQuantity.EqualizerNONE, ONE| Modifier | Constructor and Description |
|---|---|
protected |
NumberQuantity(Number number,
javax.measure.Unit<Q> unit) |
| Modifier and Type | Method and Description |
|---|---|
ComparableQuantity<Q> |
add(javax.measure.Quantity<Q> that) |
BigDecimal |
decimalValue(javax.measure.Unit<Q> unit,
MathContext ctx) |
ComparableQuantity<Q> |
divide(Number that) |
ComparableQuantity<?> |
divide(javax.measure.Quantity<?> that) |
double |
doubleValue(javax.measure.Unit<Q> unit) |
boolean |
equals(Object obj)
Compares this quantity against the specified object for strict equality (same unit and same amount).
|
Number |
getValue()
Returns the numeric value of the quantity.
|
ComparableQuantity<Q> |
inverse() |
boolean |
isBig()
Indicates if this measured amount is a big number, i.E.
|
ComparableQuantity<Q> |
multiply(Number that) |
ComparableQuantity<?> |
multiply(javax.measure.Quantity<?> that) |
static <Q extends javax.measure.Quantity<Q>> |
of(byte value,
javax.measure.Unit<Q> unit)
Returns the scalar quantity for the specified
byte stated in the specified unit. |
static <Q extends javax.measure.Quantity<Q>> |
of(double doubleValue,
javax.measure.Unit<Q> unit)
Returns the scalar quantity for the specified
double stated in the specified unit. |
static <Q extends javax.measure.Quantity<Q>> |
of(float floatValue,
javax.measure.Unit<Q> unit)
Returns the scalar quantity for the specified
float stated in the specified unit. |
static <Q extends javax.measure.Quantity<Q>> |
of(int intValue,
javax.measure.Unit<Q> unit)
Returns the scalar quantity for the specified
int stated in the specified unit. |
static <Q extends javax.measure.Quantity<Q>> |
of(long longValue,
javax.measure.Unit<Q> unit)
Returns the scalar quantity for the specified
long stated in the specified unit. |
static <Q extends javax.measure.Quantity<Q>> |
of(short value,
javax.measure.Unit<Q> unit)
Returns the scalar quantity for the specified
short stated in the specified unit. |
ComparableQuantity<Q> |
subtract(javax.measure.Quantity<Q> that) |
asType, compareTo, divide, equals, floatValue, getUnit, hashCode, intValue, inverse, isEquivalentTo, isGreaterThan, isGreaterThanOrEqualTo, isLessThan, isLessThanOrEqualTo, longValue, multiply, parse, to, to, toSI, toStringprotected NumberQuantity(Number number, javax.measure.Unit<Q> unit)
public double doubleValue(javax.measure.Unit<Q> unit)
doubleValue in class AbstractQuantity<Q extends javax.measure.Quantity<Q>>public Number getValue()
AbstractQuantitypublic boolean isBig()
isBig in class AbstractQuantity<Q extends javax.measure.Quantity<Q>>true if this quantity is big; false otherwise.public ComparableQuantity<Q> add(javax.measure.Quantity<Q> that)
public ComparableQuantity<?> multiply(javax.measure.Quantity<?> that)
public ComparableQuantity<Q> multiply(Number that)
public ComparableQuantity<?> divide(javax.measure.Quantity<?> that)
public ComparableQuantity<Q> divide(Number that)
public ComparableQuantity<Q> inverse()
public BigDecimal decimalValue(javax.measure.Unit<Q> unit, MathContext ctx) throws ArithmeticException
decimalValue in class AbstractQuantity<Q extends javax.measure.Quantity<Q>>ArithmeticExceptionpublic ComparableQuantity<Q> subtract(javax.measure.Quantity<Q> that)
public static <Q extends javax.measure.Quantity<Q>> AbstractQuantity<Q> of(long longValue, javax.measure.Unit<Q> unit)
long stated in the specified unit.longValue - the quantity value.unit - the measurement unit.int quantity.public static <Q extends javax.measure.Quantity<Q>> AbstractQuantity<Q> of(int intValue, javax.measure.Unit<Q> unit)
int stated in the specified unit.intValue - the quantity value.unit - the measurement unit.int quantity.public static <Q extends javax.measure.Quantity<Q>> AbstractQuantity<Q> of(short value, javax.measure.Unit<Q> unit)
short stated in the specified unit.value - the quantity value.unit - the measurement unit.short quantity.public static <Q extends javax.measure.Quantity<Q>> AbstractQuantity<Q> of(byte value, javax.measure.Unit<Q> unit)
byte stated in the specified unit.value - the quantity value.unit - the measurement unit.byte quantity.public static <Q extends javax.measure.Quantity<Q>> AbstractQuantity<Q> of(float floatValue, javax.measure.Unit<Q> unit)
float stated in the specified unit.floatValue - the measurement value.unit - the measurement unit.float quantity.public static <Q extends javax.measure.Quantity<Q>> AbstractQuantity<Q> of(double doubleValue, javax.measure.Unit<Q> unit)
double stated in the specified unit.doubleValue - the measurement value.unit - the measurement unit.double quantity.public boolean equals(Object obj)
AbstractQuantity
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 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
equals(Quantity, epsilon, epsilonUnit) methods should be used.
equals in class AbstractQuantity<Q extends javax.measure.Quantity<Q>>obj - the object to compare with.this.getUnit.equals(obj.getUnit())
&& this.getValue().equals(obj.getValue())Copyright © 2005–2017 Units of Measurement project. All rights reserved.