Class QuantitiesUtil

java.lang.Object
com.dlsc.unitfx.util.QuantitiesUtil

public final class QuantitiesUtil
extends Object
Utility class that allows to manipulate quantity objects.
  • Method Summary

    Modifier and Type Method Description
    static <Q extends javax.measure.Quantity<Q>>
    javax.measure.Quantity<Q>
    createQuantity​(Number value, javax.measure.Unit<Q> unit)
    Creates a new quantity instance using the given value and the given unit.
    static <Q extends javax.measure.Quantity<Q>>
    javax.measure.Quantity<Q>
    roundQuantity​(javax.measure.Quantity<Q> value, javax.measure.Quantity<Q> precision)
    Applies a rounding mechanism that returns the nearest value according to the precision.
    static <Q extends javax.measure.Quantity<Q>>
    javax.measure.Quantity<Q>
    truncateQuantity​(javax.measure.Quantity<Q> value, javax.measure.Quantity<Q> precision)
    Truncates the given quantity value to the given precision, meaning that the value is floor rounded always.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • createQuantity

      public static <Q extends javax.measure.Quantity<Q>> javax.measure.Quantity<Q> createQuantity​(Number value, javax.measure.Unit<Q> unit)
      Creates a new quantity instance using the given value and the given unit.
      Type Parameters:
      Q - The type of Quantity to be created.
      Parameters:
      value - The amount to be placed in the quantity instance.
      unit - The unit to represent the quantity.
      Returns:
      The quantity instance, null if either the value param or unit param is null.
    • truncateQuantity

      public static <Q extends javax.measure.Quantity<Q>> javax.measure.Quantity<Q> truncateQuantity​(javax.measure.Quantity<Q> value, javax.measure.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)

      Type Parameters:
      Q - The quantity type.
      Parameters:
      value - The quantity to be truncated.
      precision - The precision which the value is truncated to.
      Returns:
      A new quantity instance having the value truncated.
    • roundQuantity

      public static <Q extends javax.measure.Quantity<Q>> javax.measure.Quantity<Q> roundQuantity​(javax.measure.Quantity<Q> value, javax.measure.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)

      Type Parameters:
      Q -
      Parameters:
      value -
      precision -
      Returns: