Class Measure

  • Direct Known Subclasses:
    CurrencyAmount, TimeUnitAmount

    public class Measure
    extends java.lang.Object
    An amount of a specified unit, consisting of a Number and a Unit. For example, a length measure consists of a Number and a length unit, such as feet or meters.

    Measure objects are parsed and formatted by subclasses of MeasureFormat.

    Measure objects are immutable. All subclasses must guarantee that. (However, subclassing is discouraged.)

    See Also:
    Number, MeasureUnit, MeasureFormat
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.Number number  
      private MeasureUnit unit  
    • Constructor Summary

      Constructors 
      Constructor Description
      Measure​(java.lang.Number number, MeasureUnit unit)
      Constructs a new object given a number and a unit.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object obj)
      Returns true if the given object is equal to this object.
      java.lang.Number getNumber()
      Returns the numeric value of this object.
      MeasureUnit getUnit()
      Returns the unit of this object.
      int hashCode()
      Returns a hashcode for this object.
      private static boolean numbersEqual​(java.lang.Number a, java.lang.Number b)  
      java.lang.String toString()
      Returns a string representation of this object.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • number

        private final java.lang.Number number
    • Constructor Detail

      • Measure

        public Measure​(java.lang.Number number,
                       MeasureUnit unit)
        Constructs a new object given a number and a unit.
        Parameters:
        number - the number
        unit - the unit
    • Method Detail

      • equals

        public boolean equals​(java.lang.Object obj)
        Returns true if the given object is equal to this object.
        Overrides:
        equals in class java.lang.Object
        Returns:
        true if this object is equal to the given object
      • numbersEqual

        private static boolean numbersEqual​(java.lang.Number a,
                                            java.lang.Number b)
      • hashCode

        public int hashCode()
        Returns a hashcode for this object.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a 32-bit hash
      • toString

        public java.lang.String toString()
        Returns a string representation of this object.
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation consisting of the ISO currency code together with the numeric amount
      • getNumber

        public java.lang.Number getNumber()
        Returns the numeric value of this object.
        Returns:
        this object's Number
      • getUnit

        public MeasureUnit getUnit()
        Returns the unit of this object.
        Returns:
        this object's Unit