Top Description Constructors Methods
com.dlsc.unitfx.util

public final Class QuantitiesUtil

extends Object
Class Inheritance
Imports
tech.units.indriya.quantity.Quantities, javax.measure.Quantity, .Unit

Utility class that allows to manipulate quantity objects.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static <
The type of Quantity to be created.
Q extends Quantity<Q>
>
Quantity<Q>

Returns:

The quantity instance, null if either the value param or unit param is null.
createQuantity
(Number
The amount to be placed in the quantity instance.
value
,
Unit<Q>
The unit to represent the quantity.
unit
)

Creates a new quantity instance using the given value and the given unit.

public static <Q extends Quantity<Q>> Quantity<Q>
roundQuantity(Quantity<Q> value, Quantity<Q> precision)

Applies a rounding mechanism that returns the nearest value according to the precision.

public static <
The quantity type.
Q extends Quantity<Q>
>
Quantity<Q>

Returns:

A new quantity instance having the value truncated.
truncateQuantity
(Quantity<Q>
The quantity to be truncated.
value
,
Quantity<Q>
The precision which the value is truncated to.
precision
)

Truncates the given quantity value to the given precision, meaning that the value is floor rounded always.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

QuantitiesUtilback to summary
private QuantitiesUtil()

Method Detail

createQuantityback to summary
public static <Q extends Quantity<Q>> Quantity<Q> createQuantity(Number value, Unit<Q> unit)

Creates a new quantity instance using the given value and the given unit.

Parameters
<Q>
The type of Quantity to be created.
value:Number

The amount to be placed in the quantity instance.

unit:Unit<Q>

The unit to represent the quantity.

Returns:Quantity<Q>

The quantity instance, null if either the value param or unit param is null.

roundQuantityback to summary
public static <Q extends Quantity<Q>> Quantity<Q> roundQuantity(Quantity<Q> value, Quantity<Q> precision)

Applies a rounding mechanism that returns the nearest value according to the precision.

Examples:

  • Quantity(115 Metre), Precision(10 Metre) = Truncated(120 Metre)
  • Quantity(88 Metre), Precision(5 Metre) = Truncated(90 Metre)
  • Quantity(52 Metre), Precision(5 Metre) = Truncated(50 Metre)

truncateQuantityback to summary
public static <Q extends Quantity<Q>> Quantity<Q> truncateQuantity(Quantity<Q> value, Quantity<Q> precision)

Truncates the given quantity value to the given precision, meaning that the value is floor rounded always.

Examples:

  • Quantity(115 Metre), Precision(10 Metre) = Truncated(110 Metre)
  • Quantity(88 Metre), Precision(5 Metre) = Truncated(85 Metre)

Parameters
<Q>
The quantity type.
value:Quantity<Q>

The quantity to be truncated.

precision:Quantity<Q>

The precision which the value is truncated to.

Returns:Quantity<Q>

A new quantity instance having the value truncated.