Q - The type of the quantity.public class NumberQuantity<Q extends javax.measure.Quantity<Q>> extends AbstractQuantity<Q>
AbstractQuantity,
QuantityNONE, ONE| Constructor and Description |
|---|
NumberQuantity(Number number,
javax.measure.Unit<Q> unit)
Holds the maximum value stated in this quantity's unit.
|
| Modifier and Type | Method and Description |
|---|---|
protected javax.measure.Quantity<Q> |
add(AbstractQuantity<Q> that) |
javax.measure.Quantity<Q> |
add(javax.measure.Quantity<Q> that) |
javax.measure.Quantity<Q> |
divide(Number that) |
javax.measure.Quantity<Q> |
divide(javax.measure.Quantity<?> that) |
double |
doubleValue(javax.measure.Unit<Q> unit) |
boolean |
equals(Object obj)
Compares this measure against the specified object for strict equality (same unit and same amount).
|
Number |
getValue()
Returns the measurement numeric value.
|
protected int |
intValue(javax.measure.Unit<Q> unit) |
javax.measure.Quantity<Q> |
inverse() |
boolean |
isExact()
Indicates if this measured quantity is exact.
|
javax.measure.Quantity<Q> |
multiply(Number that) |
javax.measure.Quantity<?> |
multiply(javax.measure.Quantity<?> that) |
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. |
static javax.measure.Quantity<?> |
parse(CharSequence csq)
Returns the decimal quantity of unknown type corresponding to the specified representation.
|
javax.measure.Quantity<Q> |
subtract(javax.measure.Quantity<Q> that) |
String |
toString()
Returns the
String representation of this quantity. |
asType, compareTo, equals, floatValue, getUnit, hashCode, longValue, to, toSIpublic NumberQuantity(Number number, javax.measure.Unit<Q> unit)
public boolean equals(Object obj)
AbstractQuantity
Similarly to the BigDecimal#equals method which consider 2.0 and 2.00 as different objects because of different internal scales,
measurements such as Measure.valueOf(3.0, KILOGRAM) Measure.valueOf(3, KILOGRAM) and
Quantities.getQuantity("3 kg") might not be considered equals because of possible differences in their implementations.
To compare measures stated using different units or using different amount implementations the compareTo or
equals(Measurement, 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())public double doubleValue(javax.measure.Unit<Q> unit)
doubleValue in class AbstractQuantity<Q extends javax.measure.Quantity<Q>>protected final int intValue(javax.measure.Unit<Q> unit) throws ArithmeticException
ArithmeticExceptionpublic Number getValue()
AbstractQuantitypublic boolean isExact()
this.longValue()); stating the quantity in any other unit may introduce conversion errors.true if this quantity is exact; false otherwise.protected javax.measure.Quantity<Q> add(AbstractQuantity<Q> that)
public String toString()
AbstractQuantityString 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 class and its subclasses.toString in class AbstractQuantity<Q extends javax.measure.Quantity<Q>>UnitFormat.getInternational().format(this)public javax.measure.Quantity<?> multiply(javax.measure.Quantity<?> 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(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 static javax.measure.Quantity<?> parse(CharSequence csq)
Quatity proportion = AbstractQuantity.of("0.234").asType(Dimensionless.class);
Note: This method handles only standard unit format (UCUM based). Locale-sensitive quantity formatting and parsing are handled by the MeasurementFormat
class and its subclasses.
csq - the decimal value and its unit (if any) separated by space(s).QuantityFormat.getInstance().parse(csq)Copyright © 2005–2016 Jean-Marie Dautelle, Werner Keil, V2COM. All rights reserved.