Top Description Constructors Methods
tech.units.indriya.quantity

public final Class Quantities

extends Object
Class Inheritance
Static Imports
javax.measure.Quantity.Scale.ABSOLUTE

Facade to access Quantity instances.
Authors
Werner Keil, Otavio Santana
Since
1.0
Version
3.0, October 3, 2024

Constructor Summary

AccessConstructor and Description
private
Quantities()

Private singleton constructor.

Method Summary

Modifier and TypeMethod and Description
public static <Q extends Quantity<Q>> MixedQuantity<Q>

Returns:

the corresponding mixed quantity.
getMixedQuantity
(Number[]
the measurement values.
values
,
Unit<Q>[]
the measurement units.
units
,
Quantity.Scale
the measurement scale.
scale
)

Returns the mixed radix values and units as MixedQuantity in the specified scale.

public static <Q extends Quantity<Q>> MixedQuantity<Q>

Returns:

the corresponding mixed quantity.
getMixedQuantity
(final Number[]
the measurement values.
values
,
final Unit<Q>[]
the measurement units.
units
)

Returns the mixed radix values and units as MixedQuantity in the ABSOLUTE scale.

public static Quantity<?>

Returns:

SimpleQuantityFormat.getInstance("n u~ ").parse(csq)
getQuantity
(CharSequence
the decimal value(s) and unit(s) separated by space(s).
csq
)

Returns the scalar quantity of unknown type corresponding to the specified representation.

public static <Q extends Quantity<Q>> ComparableQuantity<Q>

Returns:

the corresponding numeric quantity.
getQuantity
(Number
the measurement value.
value
,
Unit<Q>
the measurement unit.
unit
,
Quantity.Scale
the measurement scale.
scale
)

Returns the scalar quantity of type NumberQuantity in the specified unit and scale.

public static <Q extends Quantity<Q>> ComparableQuantity<Q>

Returns:

the corresponding numeric quantity.
getQuantity
(Number
the measurement value.
value
,
Unit<Q>
the measurement unit.
unit
)

Returns the scalar quantity of type NumberQuantity in the specified unit and ABSOLUTE scale.

public static <Q extends Quantity<Q>> Quantity<Q>

Returns:

the corresponding quantity.
getQuantity
(Number[]
the measurement values.
values
,
Unit<Q>[]
the measurement units.
units
,
Quantity.Scale
the measurement scale.
scale
)

Returns the mixed radix values and units combined into a single quantity of type NumberQuantity in the specified unit and scale.

public static <Q extends Quantity<Q>> Quantity<Q>

Returns:

the corresponding quantity.
getQuantity
(Number[]
the measurement values.
values
,
Unit<Q>...
the measurement units.
units
)

Returns the mixed radix values and units combined into a single quantity in the ABSOLUTE scale.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

Quantitiesback to summary
private Quantities()

Private singleton constructor.

Method Detail

getMixedQuantityback to summary
public static <Q extends Quantity<Q>> MixedQuantity<Q> getMixedQuantity(Number[] values, Unit<Q>[] units, Quantity.Scale scale)

Returns the mixed radix values and units as MixedQuantity in the specified scale.

Parameters
values:Number[]

the measurement values.

units:Unit<Q>[]

the measurement units.

scale:Quantity.Scale

the measurement scale.

Returns:MixedQuantity<Q>

the corresponding mixed quantity.

Exceptions
NullPointerException:
if values, units or scale were null
IllegalArgumentException:
if the size of the values array does not match that of units.
Since
2.1.2
getMixedQuantityback to summary
public static <Q extends Quantity<Q>> MixedQuantity<Q> getMixedQuantity(final Number[] values, final Unit<Q>[] units)

Returns the mixed radix values and units as MixedQuantity in the ABSOLUTE scale.

Parameters
values:Number[]

the measurement values.

units:Unit<Q>[]

the measurement units.

Returns:MixedQuantity<Q>

the corresponding mixed quantity.

Exceptions
NullPointerException:
if values, units or scale were null
IllegalArgumentException:
if the size of the values array does not match that of units.
Since
2.1.2
getQuantityback to summary
public static Quantity<?> getQuantity(CharSequence csq)

Returns the scalar quantity of unknown type corresponding to the specified representation. This method can be used to parse 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.

Parameters
csq:CharSequence

the decimal value(s) and unit(s) separated by space(s).

Returns:Quantity<?>

SimpleQuantityFormat.getInstance("n u~ ").parse(csq)

Exceptions
IllegalArgumentException:
if no unit part was provided to parse
getQuantityback to summary
public static <Q extends Quantity<Q>> ComparableQuantity<Q> getQuantity(Number value, Unit<Q> unit, Quantity.Scale scale)

Returns the scalar quantity of type NumberQuantity in the specified unit and scale.

Parameters
value:Number

the measurement value.

unit:Unit<Q>

the measurement unit.

scale:Quantity.Scale

the measurement scale.

Returns:ComparableQuantity<Q>

the corresponding numeric quantity.

Exceptions
NullPointerException:
if value, unit or scale were null
Since
2.0
getQuantityback to summary
public static <Q extends Quantity<Q>> ComparableQuantity<Q> getQuantity(Number value, Unit<Q> unit)

Returns the scalar quantity of type NumberQuantity in the specified unit and ABSOLUTE scale.

Parameters
value:Number

the measurement value.

unit:Unit<Q>

the measurement unit.

Returns:ComparableQuantity<Q>

the corresponding numeric quantity.

Exceptions
NullPointerException:
when value or unit were null
getQuantityback to summary
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 type NumberQuantity in the specified unit and scale.

Parameters
values:Number[]

the measurement values.

units:Unit<Q>[]

the measurement units.

scale:Quantity.Scale

the measurement scale.

Returns:Quantity<Q>

the corresponding quantity.

Exceptions
NullPointerException:
if values or scale were null
IllegalArgumentException:
if the size of the values array does not match that of units.
Since
2.0
getQuantityback to summary
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 the ABSOLUTE scale.

Parameters
values:Number[]

the measurement values.

units:Unit<Q>[]

the measurement units.

Returns:Quantity<Q>

the corresponding quantity.

Annotations
@SafeVarargs
Exceptions
NullPointerException:
if values or units were null
IllegalArgumentException:
if the size of the values array does not match that of units.
Since
2.0