Class ShortQuantity<Q extends javax.measure.Quantity<Q>>

  • Type Parameters:
    Q - The type of the quantity.
    All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<javax.measure.Quantity<Q>>, javax.measure.Quantity<Q>, ComparableQuantity<Q>, tech.uom.lib.common.function.QuantityConverter<Q>, tech.uom.lib.common.function.UnitSupplier<Q>, tech.uom.lib.common.function.ValueSupplier<java.lang.Number>

    final class ShortQuantity<Q extends javax.measure.Quantity<Q>>
    extends AbstractQuantity<Q>
    An amount of quantity, consisting of a short and a Unit. ShortQuantity objects are immutable.
    Since:
    1.0
    Version:
    0.2, $Date: 2016-09-01 $
    See Also:
    AbstractQuantity, Quantity
    • Field Detail

      • value

        private final short value
    • Constructor Detail

      • ShortQuantity

        ShortQuantity​(short value,
                      javax.measure.Unit<Q> unit)
    • Method Detail

      • getValue

        public java.lang.Short getValue()
        Description copied from class: AbstractQuantity
        Returns the numeric value of the quantity.
        Specified by:
        getValue in interface javax.measure.Quantity<Q extends javax.measure.Quantity<Q>>
        Specified by:
        getValue in interface tech.uom.lib.common.function.ValueSupplier<Q extends javax.measure.Quantity<Q>>
        Specified by:
        getValue in class AbstractQuantity<Q extends javax.measure.Quantity<Q>>
        Returns:
        the quantity value.
      • doubleValue

        public double doubleValue​(javax.measure.Unit<Q> unit)
        Specified by:
        doubleValue in class AbstractQuantity<Q extends javax.measure.Quantity<Q>>
      • longValue

        public long longValue​(javax.measure.Unit<Q> unit)
        Overrides:
        longValue in class AbstractQuantity<Q extends javax.measure.Quantity<Q>>
      • isBig

        public boolean isBig()
        Specified by:
        isBig in class AbstractQuantity<Q extends javax.measure.Quantity<Q>>
      • decimalValue

        public java.math.BigDecimal decimalValue​(javax.measure.Unit<Q> unit)
        Specified by:
        decimalValue in class AbstractQuantity<Q extends javax.measure.Quantity<Q>>
      • isOverflowing

        private boolean isOverflowing​(double value)
      • addRaw

        private ComparableQuantity<Q> addRaw​(java.lang.Number a,
                                             java.lang.Number b,
                                             javax.measure.Unit<Q> unit)
      • add

        public ComparableQuantity<Q> add​(javax.measure.Quantity<Q> that)
        See Also:
        Quantity.add(Quantity)
      • subtract

        public ComparableQuantity<Q> subtract​(javax.measure.Quantity<Q> that)
        See Also:
        Quantity.subtract(Quantity)
      • divide

        public ComparableQuantity<?> divide​(javax.measure.Quantity<?> that)
        See Also:
        Quantity.divide(Quantity)
      • divide

        public ComparableQuantity<Q> divide​(java.lang.Number that)
        See Also:
        Quantity.divide(Number)
      • multiply

        public ComparableQuantity<?> multiply​(javax.measure.Quantity<?> multiplier)
        See Also:
        Quantity.multiply(Quantity)
      • multiply

        public ComparableQuantity<Q> multiply​(java.lang.Number multiplier)
        See Also:
        Quantity.multiply(Number)
      • equals

        public boolean equals​(java.lang.Object obj)
        Description copied from class: AbstractQuantity
        Compares this quantity against the specified object for strict equality (same unit and same amount).

        Similarly to the BigDecimal.equals(java.lang.Object) method which consider 2.0 and 2.00 as different objects because of different internal scales, quantities such as Quantities.getQuantity(3.0, KILOGRAM) Quantities.getQuantity(3, KILOGRAM) and Quantities.getQuantity("3 kg") might not be considered equals because of possible differences in their implementations.

        To compare quantities stated using different units or using different amount implementations the compareTo or equals(Quantity, epsilon, epsilonUnit) methods should be used.

        Overrides:
        equals in class AbstractQuantity<Q extends javax.measure.Quantity<Q>>
        Parameters:
        obj - the object to compare with.
        Returns:
        this.getUnit.equals(obj.getUnit()) && this.getValue().equals(obj.getValue())