public final class Quantities extends Object
Quantity instances.| Modifier and Type | Method and Description |
|---|---|
static <Q extends javax.measure.Quantity<Q>> |
getCompoundQuantity(Number[] values,
javax.measure.Unit<Q>[] units)
Deprecated.
|
static <Q extends javax.measure.Quantity<Q>> |
getCompoundQuantity(Number[] values,
javax.measure.Unit<Q>[] units,
javax.measure.Quantity.Scale scale)
Deprecated.
use
#getMixedQuantity(Number[], Unit[], Scale) |
static <Q extends javax.measure.Quantity<Q>> |
getMixedQuantity(Number[] values,
javax.measure.Unit<Q>[] units)
Returns the mixed radix values and units as
MixedQuantity in the
ABSOLUTE scale. |
static <Q extends javax.measure.Quantity<Q>> |
getMixedQuantity(Number[] values,
javax.measure.Unit<Q>[] units,
javax.measure.Quantity.Scale scale)
Returns the mixed radix values and units as
MixedQuantity in the
specified scale. |
static javax.measure.Quantity<?> |
getQuantity(CharSequence csq)
Returns the scalar quantity of unknown type corresponding to the specified
representation.
|
static <Q extends javax.measure.Quantity<Q>> |
getQuantity(Number[] values,
javax.measure.Unit<Q>... units)
Returns the mixed radix values and units combined into a single quantity in
the
ABSOLUTE scale. |
static <Q extends javax.measure.Quantity<Q>> |
getQuantity(Number[] values,
javax.measure.Unit<Q>[] units,
javax.measure.Quantity.Scale scale)
Returns the mixed radix values and units combined into a single quantity.
|
static <Q extends javax.measure.Quantity<Q>> |
getQuantity(Number value,
javax.measure.Unit<Q> unit)
Returns the scalar quantity.
|
static <Q extends javax.measure.Quantity<Q>> |
getQuantity(Number value,
javax.measure.Unit<Q> unit,
javax.measure.Quantity.Scale scale)
Returns the scalar quantity.
|
public static javax.measure.Quantity<?> getQuantity(CharSequence csq)
mixed
quantities. All of these expressions:
Quantity<Length> height = Quantities.getQuantity("1.70 m").asType(Length.class);
Quantity<Length> heightinCm = Quantities.getQuantity("170 cm").asType(Length.class);
Quantity<Length> heightMixed = Quantities.getQuantity("1 m 70 cm").asType(Length.class);
are equally supported.
Note: This method handles only Locale-neutral quantity formatting and parsing
are handled by the SimpleQuantityFormat class.
Due to the versatile parsing of this method recognizing both single and mixed quantities, a unit must be provided, otherwise it'll fail.
If you need to parse a unit-less quantity, please use the parse() method of AbstractQuantity instead.
csq - the decimal value(s) and unit(s) separated by space(s).SimpleQuantityFormat.getInstance("n u~ ").parse(csq)IllegalArgumentException - if no unit part was provided to parsepublic static <Q extends javax.measure.Quantity<Q>> ComparableQuantity<Q> getQuantity(Number value, javax.measure.Unit<Q> unit, javax.measure.Quantity.Scale scale)
Number was BigDecimal
or BigInteger will uses DecimalQuantity, when the
Number was Double will DoubleQuantity otherwise will
NumberQuantity. in the specified unit.value - the measurement value.unit - the measurement unit.scale - the measurement scale.numeric quantity.NullPointerException - if value, unit or scale were nullpublic static <Q extends javax.measure.Quantity<Q>> ComparableQuantity<Q> getQuantity(Number value, javax.measure.Unit<Q> unit)
Number was BigDecimal
or BigInteger will uses DecimalQuantity, when the
Number was Double will DoubleQuantity otherwise will
NumberQuantity. in the specified unit.value - the measurement value.unit - the measurement unit.numeric quantity.NullPointerException - when value or unit were nullpublic static <Q extends javax.measure.Quantity<Q>> javax.measure.Quantity<Q> getQuantity(Number[] values, javax.measure.Unit<Q>[] units, javax.measure.Quantity.Scale scale)
Number was BigDecimal or BigInteger will
uses DecimalQuantity, when the Number was Double will
DoubleQuantity otherwise will NumberQuantity. in the
specified unit.values - the measurement values.units - the measurement units.scale - the measurement scale.NullPointerException - if values or scale were nullIllegalArgumentException - if the size of the values array does not
match that of units.@SafeVarargs public static <Q extends javax.measure.Quantity<Q>> javax.measure.Quantity<Q> getQuantity(Number[] values, javax.measure.Unit<Q>... units)
ABSOLUTE scale.values - the measurement values.units - the measurement units.NullPointerException - if values or units were nullIllegalArgumentException - if the size of the values array does not
match that of units.public static <Q extends javax.measure.Quantity<Q>> MixedQuantity<Q> getMixedQuantity(Number[] values, javax.measure.Unit<Q>[] units, javax.measure.Quantity.Scale scale)
MixedQuantity in the
specified scale.values - the measurement values.units - the measurement units.scale - the measurement scale.NullPointerException - if values, units or scale were nullIllegalArgumentException - if the size of the values array does not
match that of units.public static <Q extends javax.measure.Quantity<Q>> MixedQuantity<Q> getMixedQuantity(Number[] values, javax.measure.Unit<Q>[] units)
MixedQuantity in the
ABSOLUTE scale.values - the measurement values.units - the measurement units.NullPointerException - if values, units or scale were nullIllegalArgumentException - if the size of the values array does not
match that of units.public static <Q extends javax.measure.Quantity<Q>> CompoundQuantity<Q> getCompoundQuantity(Number[] values, javax.measure.Unit<Q>[] units, javax.measure.Quantity.Scale scale)
#getMixedQuantity(Number[], Unit[], Scale)CompoundQuantity in the
specified scale.values - the measurement values.units - the measurement units.scale - the measurement scale.NullPointerException - if values, units or scale were nullIllegalArgumentException - if the size of the values array does not
match that of units.public static <Q extends javax.measure.Quantity<Q>> CompoundQuantity<Q> getCompoundQuantity(Number[] values, javax.measure.Unit<Q>[] units)
getMixedQuantity(Number[], Unit[])CompoundQuantity in the
ABSOLUTE scale.values - the measurement values.units - the measurement units.NullPointerException - if values, units or scale were nullIllegalArgumentException - if the size of the values array does not
match that of units.Copyright © 2005–2022 Units of Measurement project. All rights reserved.