Package tech.units.indriya.quantity
Class Quantities
- java.lang.Object
-
- tech.units.indriya.quantity.Quantities
-
public final class Quantities extends Object
Singleton class for accessingQuantityinstances.- Since:
- 1.0
- Version:
- 1.10, April 20, 2019
- Author:
- keilw, otaviojava
-
-
Method Summary
Modifier and Type Method Description static <Q extends javax.measure.Quantity<Q>>
CompoundQuantity<Q>getCompoundQuantity(Number[] values, javax.measure.Unit<Q>[] units)Returns the mixed radix values and units asCompoundQuantityin theABSOLUTEscale.static <Q extends javax.measure.Quantity<Q>>
CompoundQuantity<Q>getCompoundQuantity(Number[] values, javax.measure.Unit<Q>[] units, javax.measure.Quantity.Scale scale)Returns the mixed radix values and units asCompoundQuantityin the specified scale.static javax.measure.Quantity<?>getQuantity(CharSequence csq)Returns thedecimalquantity of unknown type corresponding to the specified representation.static <Q extends javax.measure.Quantity<Q>>
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 theABSOLUTEscale.static <Q extends javax.measure.Quantity<Q>>
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>>
ComparableQuantity<Q>getQuantity(Number value, javax.measure.Unit<Q> unit)Returns the scalar quantity.static <Q extends javax.measure.Quantity<Q>>
ComparableQuantity<Q>getQuantity(Number value, javax.measure.Unit<Q> unit, javax.measure.Quantity.Scale scale)Returns the scalar quantity.
-
-
-
Method Detail
-
getQuantity
public static javax.measure.Quantity<?> getQuantity(CharSequence csq)
Returns thedecimalquantity of unknown type corresponding to the specified representation. This method can be used to parse dimensionless quantities.
Quantityproportion = Quantities.getQuantity("0.234").asType(Dimensionless.class); Note: This method handles only Locale-neutral quantity formatting and parsing are handled by the
AbstractQuantityFormatclass and its subclasses.- Parameters:
csq- the decimal value and its unit (if any) separated by space(s).- Returns:
QuantityFormat.getInstance(LOCALE_NEUTRAL).parse(csq)
-
getQuantity
public static <Q extends javax.measure.Quantity<Q>> ComparableQuantity<Q> getQuantity(Number value, javax.measure.Unit<Q> unit, javax.measure.Quantity.Scale scale)
Returns the scalar quantity. When theNumberwasBigDecimalorBigIntegerwill usesDecimalQuantity, when theNumberwasDoublewillDoubleQuantityotherwise willNumberQuantity. in the specified unit.- Parameters:
value- the measurement value.unit- the measurement unit.scale- the measurement scale.- Returns:
- the corresponding
numericquantity. - Throws:
NullPointerException- if value, unit or scale were nulljavax.measure.MeasurementException- if unit is a MixedUnit- Since:
- 2.0
-
getQuantity
public static <Q extends javax.measure.Quantity<Q>> ComparableQuantity<Q> getQuantity(Number value, javax.measure.Unit<Q> unit)
Returns the scalar quantity. When theNumberwasBigDecimalorBigIntegerwill usesDecimalQuantity, when theNumberwasDoublewillDoubleQuantityotherwise willNumberQuantity. in the specified unit.- Parameters:
value- the measurement value.unit- the measurement unit.- Returns:
- the corresponding
numericquantity. - Throws:
NullPointerException- when value or unit were null
-
getQuantity
public static <Q extends javax.measure.Quantity<Q>> 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. When theNumberwasBigDecimalorBigIntegerwill usesDecimalQuantity, when theNumberwasDoublewillDoubleQuantityotherwise willNumberQuantity. in the specified unit.- Parameters:
values- the measurement values.units- the measurement units.scale- the measurement scale.- Returns:
- the corresponding quantity.
- Throws:
NullPointerException- if value or scale were nullIllegalArgumentException- if the size of the values array does not match that of units.- Since:
- 2.0
-
getQuantity
@SafeVarargs public static <Q extends javax.measure.Quantity<Q>> 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 theABSOLUTEscale.- Parameters:
values- the measurement values.units- the measurement units.- Returns:
- the corresponding quantity.
- Throws:
NullPointerException- if value or unit were nullIllegalArgumentException- if the size of the values array does not match that of units.- Since:
- 2.0
-
getCompoundQuantity
public static <Q extends javax.measure.Quantity<Q>> CompoundQuantity<Q> getCompoundQuantity(Number[] values, javax.measure.Unit<Q>[] units, javax.measure.Quantity.Scale scale)
Returns the mixed radix values and units asCompoundQuantityin the specified scale.- Parameters:
values- the measurement values.units- the measurement units.scale- the measurement scale.- Returns:
- the corresponding compound quantity.
- Throws:
NullPointerException- if values, units or scale were nullIllegalArgumentException- if the size of the values array does not match that of units.- Since:
- 2.0
-
getCompoundQuantity
public static <Q extends javax.measure.Quantity<Q>> CompoundQuantity<Q> getCompoundQuantity(Number[] values, javax.measure.Unit<Q>[] units)
Returns the mixed radix values and units asCompoundQuantityin theABSOLUTEscale.- Parameters:
values- the measurement values.units- the measurement units.- Returns:
- the corresponding compound quantity.
- Throws:
NullPointerException- if values, units or scale were nullIllegalArgumentException- if the size of the values array does not match that of units.- Since:
- 2.0
-
-