Class UnitValue


  • public class UnitValue
    extends java.lang.Object
    A specialized class that holds a value and the unit it is measured in.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int PERCENT  
      static int POINT  
      protected int unitType  
      protected float value  
    • Constructor Summary

      Constructors 
      Constructor Description
      UnitValue​(int unitType, float value)
      Creates a UnitValue object with a specified type and value.
      UnitValue​(UnitValue unitValue)
      Creates a copy of UnitValue object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static UnitValue[] createPercentArray​(float[] values)
      Creates an array of UnitValue PERCENT objects with specified values.
      static UnitValue[] createPercentArray​(int size)
      Creates an array of UnitValue PERCENT objects with equal values.
      static UnitValue createPercentValue​(float value)
      Creates a UnitValue PERCENT object with a specified value.
      static UnitValue[] createPointArray​(float[] values)
      Creates an array of UnitValue POINT objects with specified values.
      static UnitValue createPointValue​(float value)
      Creates a UnitValue POINT object with a specified value.
      boolean equals​(java.lang.Object obj)  
      int getUnitType()
      Returns the unit this value is stored in, either points (pt) or percent(%)
      float getValue()
      Gets the measured value stored in this object
      int hashCode()  
      boolean isPercentValue()
      Returns whether or not the value is stored in percent (%)
      boolean isPointValue()
      Returns whether or not the value is stored in points (pt)
      void setUnitType​(int unitType)
      Sets the unit this value is stored in, either points (pt) or percent(%)
      void setValue​(float value)
      Sets the measured value stored in this object
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • UnitValue

        public UnitValue​(int unitType,
                         float value)
        Creates a UnitValue object with a specified type and value.
        Parameters:
        unitType - either POINT or a PERCENT
        value - the value to be stored.
      • UnitValue

        public UnitValue​(UnitValue unitValue)
        Creates a copy of UnitValue object.
        Parameters:
        unitValue - the value to be stored
    • Method Detail

      • createPointValue

        public static UnitValue createPointValue​(float value)
        Creates a UnitValue POINT object with a specified value.
        Parameters:
        value - the value to be stored.
        Returns:
        a new POINT UnitValue
      • createPercentValue

        public static UnitValue createPercentValue​(float value)
        Creates a UnitValue PERCENT object with a specified value.
        Parameters:
        value - the value to be stored.
        Returns:
        a new PERCENT UnitValue
      • createPercentArray

        public static UnitValue[] createPercentArray​(float[] values)
        Creates an array of UnitValue PERCENT objects with specified values.
        Parameters:
        values - the values to be stored.
        Returns:
        a new normalized (Σ=100%) array of PERCENT UnitValue.
      • createPercentArray

        public static UnitValue[] createPercentArray​(int size)
        Creates an array of UnitValue PERCENT objects with equal values.
        Parameters:
        size - of the resulted array.
        Returns:
        a array of equal PERCENT UnitValue.
      • createPointArray

        public static UnitValue[] createPointArray​(float[] values)
        Creates an array of UnitValue POINT objects with specified values.
        Parameters:
        values - the values to be stored.
        Returns:
        a new array of POINT UnitValue
      • getUnitType

        public int getUnitType()
        Returns the unit this value is stored in, either points (pt) or percent(%)
        Returns:
        either 1 for POINT or 2 for PERCENT
      • setUnitType

        public void setUnitType​(int unitType)
        Sets the unit this value is stored in, either points (pt) or percent(%)
        Parameters:
        unitType - either POINT or PERCENT
      • getValue

        public float getValue()
        Gets the measured value stored in this object
        Returns:
        the value, as a float
      • setValue

        public void setValue​(float value)
        Sets the measured value stored in this object
        Parameters:
        value - a float
      • isPointValue

        public boolean isPointValue()
        Returns whether or not the value is stored in points (pt)
        Returns:
        true if stored in points
      • isPercentValue

        public boolean isPercentValue()
        Returns whether or not the value is stored in percent (%)
        Returns:
        true if stored in percent
      • equals

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

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

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object