Package tech.units.indriya.quantity
Class Quantities
- java.lang.Object
-
- tech.units.indriya.quantity.Quantities
-
public final class Quantities extends Object
Facade to accessQuantityinstances.- Since:
- 1.0
- Version:
- 3.0, October 3, 2024
- Author:
- Werner Keil, Otavio Santana
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <Q extends Quantity<Q>>
MixedQuantity<Q>getMixedQuantity(Number[] values, Unit<Q>[] units)Returns the mixed radix values and units asMixedQuantityin theABSOLUTEscale.static <Q extends Quantity<Q>>
MixedQuantity<Q>getMixedQuantity(Number[] values, Unit<Q>[] units, Quantity.Scale scale)Returns the mixed radix values and units asMixedQuantityin the specified scale.static Quantity<?>getQuantity(CharSequence csq)Returns the scalar quantity of unknown type corresponding to the specified representation.static <Q extends Quantity<Q>>
Quantity<Q>getQuantity(Number[] values, Unit<Q>... units)Returns the mixed radix values and units combined into a single quantity in theABSOLUTEscale.static <Q extends Quantity<Q>>
Quantity<Q>getQuantity(Number[] values, Unit<Q>[] units, Quantity.Scale scale)Returns the mixed radix values and units combined into a single quantity of typeNumberQuantityin the specified unit and scale.static <Q extends Quantity<Q>>
ComparableQuantity<Q>getQuantity(Number value, Unit<Q> unit)Returns the scalar quantity of typeNumberQuantityin the specified unit andABSOLUTEscale.static <Q extends Quantity<Q>>
ComparableQuantity<Q>getQuantity(Number value, Unit<Q> unit, Quantity.Scale scale)Returns the scalar quantity of typeNumberQuantityin the specified unit and scale.
-
-
-
Method Detail
-
getQuantity
public static Quantity<?> getQuantity(CharSequence csq)
Returns the scalar quantity of unknown type corresponding to the specified representation. This method can be used to parsemixedquantities. All of these expressions:
Quantity<Length> height = Quantities.getQuantity("1.70 m").asType(Length.class);are equally supported.
Quantity<Length> heightinCm = Quantities.getQuantity("170 cm").asType(Length.class);
Quantity<Length> heightMixed = Quantities.getQuantity("1 m 70 cm").asType(Length.class);Note: This method handles only
Locale-neutral quantity formatting and parsing are handled by theSimpleQuantityFormatclass.
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 theparse()method ofAbstractQuantityinstead.- Parameters:
csq- the decimal value(s) and unit(s) separated by space(s).- Returns:
SimpleQuantityFormat.getInstance("n u~ ").parse(csq)- Throws:
IllegalArgumentException- if no unit part was provided to parse
-
getQuantity
public static <Q extends Quantity<Q>> ComparableQuantity<Q> getQuantity(Number value, Unit<Q> unit, Quantity.Scale scale)
Returns the scalar quantity of typeNumberQuantityin the specified unit and scale.- 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 null- Since:
- 2.0
-
getQuantity
public static <Q extends Quantity<Q>> ComparableQuantity<Q> getQuantity(Number value, Unit<Q> unit)
Returns the scalar quantity of typeNumberQuantityin the specified unit andABSOLUTEscale.- 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 Quantity<Q>> Quantity<Q> getQuantity(Number[] values, Unit<Q>[] units, Quantity.Scale scale)
Returns the mixed radix values and units combined into a single quantity of typeNumberQuantityin the specified unit and scale.- Parameters:
values- the measurement values.units- the measurement units.scale- the measurement scale.- Returns:
- the corresponding quantity.
- Throws:
NullPointerException- if values 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 Quantity<Q>> Quantity<Q> getQuantity(Number[] values, 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 values or units were nullIllegalArgumentException- if the size of the values array does not match that of units.- Since:
- 2.0
-
getMixedQuantity
public static <Q extends Quantity<Q>> MixedQuantity<Q> getMixedQuantity(Number[] values, Unit<Q>[] units, Quantity.Scale scale)
Returns the mixed radix values and units asMixedQuantityin the specified scale.- Parameters:
values- the measurement values.units- the measurement units.scale- the measurement scale.- Returns:
- the corresponding mixed 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.1.2
-
getMixedQuantity
public static <Q extends Quantity<Q>> MixedQuantity<Q> getMixedQuantity(Number[] values, Unit<Q>[] units)
Returns the mixed radix values and units asMixedQuantityin theABSOLUTEscale.- Parameters:
values- the measurement values.units- the measurement units.- Returns:
- the corresponding mixed 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.1.2
-
-