Class Quantities


  • public final class Quantities
    extends Object
    Singleton class for accessing Quantity instances.
    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 as CompoundQuantity in the ABSOLUTE scale.
      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 as CompoundQuantity in the specified scale.
      static javax.measure.Quantity<?> getQuantity​(CharSequence csq)
      Returns the decimal quantity 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 the ABSOLUTE scale.
      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 the decimal quantity of unknown type corresponding to the specified representation. This method can be used to parse dimensionless quantities.
        Quantity proportion = Quantities.getQuantity("0.234").asType(Dimensionless.class);

        Note: This method handles only Locale-neutral quantity formatting and parsing are handled by the AbstractQuantityFormat class 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 the Number was BigDecimal or BigInteger will uses DecimalQuantity, when the Number was Double will DoubleQuantity otherwise will NumberQuantity. in the specified unit.
        Parameters:
        value - the measurement value.
        unit - the measurement unit.
        scale - the measurement scale.
        Returns:
        the corresponding numeric quantity.
        Throws:
        NullPointerException - if value, unit or scale were null
        javax.measure.MeasurementException - if unit is a MixedUnit
        Since:
        2.0
      • 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 the Number was BigDecimal or BigInteger will uses DecimalQuantity, when the Number was Double will DoubleQuantity otherwise will NumberQuantity. 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 null
        IllegalArgumentException - 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 the ABSOLUTE scale.
        Parameters:
        values - the measurement values.
        units - the measurement units.
        Returns:
        the corresponding quantity.
        Throws:
        NullPointerException - if value or unit were null
        IllegalArgumentException - 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 as CompoundQuantity in 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 null
        IllegalArgumentException - 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 as CompoundQuantity in the ABSOLUTE scale.
        Parameters:
        values - the measurement values.
        units - the measurement units.
        Returns:
        the corresponding compound quantity.
        Throws:
        NullPointerException - if values, units or scale were null
        IllegalArgumentException - if the size of the values array does not match that of units.
        Since:
        2.0