Class ScalarQuantity<U extends TypedUnit<U>>

    • Constructor Detail

      • ScalarQuantity

        protected ScalarQuantity​(U unit)
    • Method Detail

      • compareTo

        public int compareTo​(IQuantity other)
        Specified by:
        compareTo in interface java.lang.Comparable<U extends TypedUnit<U>>
      • equals

        public abstract boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public abstract int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • in

        public IQuantity in​(IUnit targetUnit)
        Description copied from interface: IQuantity
        Get this quantity expressed in the unit targetUnit. Note that as a result of this conversion, precision may be lost. Partly due to that fact, this method should generally not be used. If the ultimate goal is some pure numerical value, there are more suitable methods, some of which are listed below, which directly provides such values. In either case, the quantity returned from this method should not be kept alive, as the original quantity provides better precision.
        Specified by:
        in in interface IQuantity
        Returns:
        a quantity, with approximately the same value as this quantity, expressed in targetUnit
        See Also:
        IQuantity.doubleValueIn(IUnit), IQuantity.numberValueIn(IUnit), IQuantity.clampedLongValueIn(IUnit), IQuantity.ratioTo(IQuantity)
      • in

        public ITypedQuantity<U> in​(U targetUnit)
        Description copied from interface: ITypedQuantity
        Get this quantity expressed in the unit targetUnit. Note that as a result of this conversion, precision may be lost. Note that this method differs from IQuantity.in(IUnit) only by stricter typing.
        Specified by:
        in in interface ITypedQuantity<U extends TypedUnit<U>>
        Returns:
        a quantity, with approximately the same value as this quantity, expressed in targetUnit
      • interactiveFormat

        public final java.lang.String interactiveFormat()
        Description copied from interface: IQuantity
        An exact string representation taking locale and internationalization into account. When parsed using KindOfQuantity.parseInteractive(String) (by this quantity's kind of quantity), in the same locale, yields a value that is equal to this quantity. That is, the exact representation must be preserved.
        Specified by:
        interactiveFormat in interface IQuantity
        Returns:
        a string representation taking locale and internationalization into account.
      • displayUsing

        public java.lang.String displayUsing​(java.lang.String formatIdentifier)
        Description copied from interface: IDisplayable
        Format this object for display purposes, preferably using the formatter hinted by formatHint. If no such formatter is defined for this type, the default formatter will be used.
        Specified by:
        displayUsing in interface IDisplayable
        Parameters:
        formatIdentifier - the format hint
        Returns:
        a formatted string according to the hinted (or default) formatter
      • isLinear

        public boolean isLinear()
        Description copied from interface: IQuantity
        If this quantity is linear. That is, if quantities of the same kind can be added to and subtracted from it, and the resulting quantity remains of the same kind.
        Specified by:
        isLinear in interface IQuantity
        Returns:
        true iff the quantity is linear
      • add

        public IQuantity add​(IQuantity addend)
                      throws java.lang.IllegalArgumentException
        Description copied from interface: IQuantity
        Returns a new quantity that is the arithmetic sum of this quantity and addend, if such an operation is defined for this kind of quantity. This operation is commutative, so that a.add(b) produces the same result, or throws the same kind of exception, as b.add(a).

        Note that if this quantity is linear, adding a quantity of the same kind is guaranteed to succeed and produces a quantity of the same kind. Also, the sum of a non-linear quantity and a linear quantity of a specific related (delta) kind of quantity is defined and produces a non-linear quantity. However, two non-linear quantities may never be added.

        Specified by:
        add in interface IQuantity
        Returns:
        the sum of this quantity and addend
        Throws:
        java.lang.IllegalArgumentException - if addend is not of a compatible kind of quantity
      • subtract

        public IQuantity subtract​(IQuantity subtrahend)
                           throws java.lang.IllegalArgumentException
        Description copied from interface: IQuantity
        Returns a new quantity that is the arithmetic difference of this quantity and subtrahend, if such an operation is defined for this kind of quantity. This operation is anti-commutative when this quantity and subtrahend are of the same kind. That is, when the result is linear.

        Quantities of the same kind may be subtracted, giving a linear result. Additionally, a linear quantity may be subtracted from a non-linear quantity, provided their kinds are related.

        Specified by:
        subtract in interface IQuantity
        Returns:
        the difference of this quantity and subtrahend
        Throws:
        java.lang.IllegalArgumentException - if subtrahend is not of a compatible kind of quantity