Class MoneyToken

    • Field Detail

      • NULL

        public static final MoneyToken NULL
        A null valued MoneyToken
      • ZERO_VALUE

        public static final long ZERO_VALUE
        The money zero value, 0.00.
        See Also:
        Constant Field Values
      • ZERO

        public static final MoneyToken ZERO
        A zero valued MoneyToken
    • Constructor Detail

      • MoneyToken

        public MoneyToken​(MoneyValued value)
        Constructs a new token with the money value in the given container.
        Parameters:
        value - a MoneyValued containing the desired value
      • MoneyToken

        public MoneyToken​(long value)
        Constructs a new token with the given non-null money value. If a null valued token is desired, use NULL.
        Parameters:
        value - the money value of the token in cents
      • MoneyToken

        public MoneyToken​(float value)
        Constructs a new token with the given non-null money value. If a null valued token is desired, use NULL.
        Parameters:
        value - the money value of the token
      • MoneyToken

        public MoneyToken​(double value)
        Constructs a new token with the given non-null money value. If a null valued token is desired, use NULL.
        Parameters:
        value - the money value of the token
    • Method Detail

      • equals

        public boolean equals​(Object obj)
        Description copied from interface: DataToken
        Indicates whether another object is equal to this token. Two null valued tokens are considered equal. This differs from the behavior of TokenComparator.equal(TokenValued,TokenValued) but makes it possible to store DataTokens in Maps.
        Specified by:
        equals in interface DataToken
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare
        Returns:
        true if the other object is a token of the same type and contains the same value, false otherwise.
      • hashCode

        public int hashCode()
        Description copied from interface: DataToken
        Returns a hash code for the token. This value is guaranteed to be consistent with that returned by TokenConverter.asHashCode(TokenValued).
        Specified by:
        hashCode in interface DataToken
        Overrides:
        hashCode in class Object
        Returns:
        a hash code value for the token
      • parse

        public static MoneyToken parse​(String value)
        Converts a string representation of a money value into a token.
        Parameters:
        value - a string value to interpret as money; see BigDecimal#valueOf(String)
        Returns:
        a token with the specified value
      • asDouble

        public final double asDouble()
        Description copied from interface: DoubleValued
        Gets the contained double value.
        Specified by:
        asDouble in interface DoubleValued
        Returns:
        the contained value as a double. If null valued, as indicated by TokenValued.isNull(), Double.NaN is returned.
      • asFloat

        public final float asFloat()
        Description copied from interface: FloatValued
        Gets the contained float value.
        Specified by:
        asFloat in interface FloatValued
        Returns:
        the contained value as a float. If null valued, as indicated by TokenValued.isNull(), Float.NaN is returned.
      • asCents

        public final long asCents()
        Description copied from interface: MoneyValued
        Gets the contained cents value as a long
        Specified by:
        asCents in interface MoneyValued
        Returns:
        the contained cents value as a long. If null valued, as indicated by TokenValued.isNull(), 0 is returned.
      • isZero

        public final boolean isZero()
        Description copied from interface: ScalarValued
        Indicates whether the value is the zero value for the type. Zero values are not stored in sparse representation formats.
        Specified by:
        isZero in interface ScalarValued
        Returns:
        true if the value is the zero value, false otherwise.
      • isNull

        public final boolean isNull()
        Description copied from interface: TokenValued
        Indicates whether the token is null valued. Tokens support null values analogous to SQL. Before accessing the value of the container, it is usually best to ensure it is not null valued using this method.
        Specified by:
        isNull in interface TokenValued
        Returns:
        true if the token is null valued, false otherwise