Class Length

  • All Implemented Interfaces:
    java.io.Serializable

    public class Length
    extends java.lang.Object
    implements java.io.Serializable
    Provides a length measurement that can be expressed using the preferred units of length.
    Author:
    Joel HÃ¥kansson
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Length.UnitsOfLength
      Defines possible units to be used when expressing a length value
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static double INCH_IN_MM  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double asInches()
      Gets the value of this length, expressed in inch units
      double asMillimeter()
      Gets the value of this length, expressed in millimeter units
      boolean equals​(java.lang.Object object)  
      double getLength()
      Gets the length, expressed in the original units of length.
      Length.UnitsOfLength getUnitsOfLength()
      Gets the original units of length.
      int hashCode()  
      static Length newCentimeterValue​(double value)
      Creates a new Length object with the specified value, expressed in centimeter units
      static Length newInchValue​(double value)
      Creates a new Length object with the specified value, expressed in inch units
      static Length newMillimeterValue​(double value)
      Creates a new Length object with the specified value, expressed in millimeter units
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

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

      • getLength

        public double getLength()
        Gets the length, expressed in the original units of length.
        Returns:
        returns the length
      • getUnitsOfLength

        public Length.UnitsOfLength getUnitsOfLength()
        Gets the original units of length.
        Returns:
        returns the original units of length
      • asMillimeter

        public double asMillimeter()
        Gets the value of this length, expressed in millimeter units
        Returns:
        returns the value
      • asInches

        public double asInches()
        Gets the value of this length, expressed in inch units
        Returns:
        returns the value
      • newMillimeterValue

        public static Length newMillimeterValue​(double value)
        Creates a new Length object with the specified value, expressed in millimeter units
        Parameters:
        value - the length in millimeters
        Returns:
        returns a new Length object
      • newCentimeterValue

        public static Length newCentimeterValue​(double value)
        Creates a new Length object with the specified value, expressed in centimeter units
        Parameters:
        value - the length in centimeter
        Returns:
        returns a new Length object
      • newInchValue

        public static Length newInchValue​(double value)
        Creates a new Length object with the specified value, expressed in inch units
        Parameters:
        value - the length in inches
        Returns:
        returns a new Length object
      • toString

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

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

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