Enum DistanceUnit

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<DistanceUnit>

    public enum DistanceUnit
    extends java.lang.Enum<DistanceUnit>
    An enum for expressing distance units. Contains everything needed for conversions and others.
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      CM
      Represents the centimeter unit.
      DEGREES
      Represents the lat long degree unit.
      FT
      Represents the american foot unit.
      IN
      Represents the american inch unit.
      KM
      Represents the kilometer unit.
      M
      Represents the meter unit.
      MI
      Represents the american mile unit.
      MINUTE
      Represents the lat long minute unit.
      MM
      Represents the millimeter unit.
      PC
      Represents the pica unit.
      PT
      Represents the point unit.
      PX
      Represents the pixel unit.
      SECOND
      Represents the lat long second unit.
      YD
      Represents the american yard unit.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      double convertTo​(double value, DistanceUnit targetUnit)
      Convert values in this unit to the equivalent value in another unit.
      static DistanceUnit fromProjection​(org.geotools.api.referencing.crs.CoordinateReferenceSystem projection)
      Determine the unit of the given projection.
      static DistanceUnit fromString​(java.lang.String val)
      Parse the value and return the identified unit object.
      DistanceUnit[] getAllUnits()
      Return the sorted list (from smallest to biggest) of units sharing the same base unit.
      static DistanceUnit getBestUnit​(double value, DistanceUnit unit)
      Return the first unit that would give a value >=1.
      boolean isBase()  
      boolean isSameBaseUnit​(DistanceUnit target)
      Check if this unit and the target unit have the same "base" unit IE inches and feet have same base unit.
      java.lang.String toString()  
      static DistanceUnit valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static DistanceUnit[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • M

        public static final DistanceUnit M
        Represents the meter unit.
      • MM

        public static final DistanceUnit MM
        Represents the millimeter unit.
      • CM

        public static final DistanceUnit CM
        Represents the centimeter unit.
      • KM

        public static final DistanceUnit KM
        Represents the kilometer unit.
      • FT

        public static final DistanceUnit FT
        Represents the american foot unit.
      • IN

        public static final DistanceUnit IN
        Represents the american inch unit.
      • YD

        public static final DistanceUnit YD
        Represents the american yard unit.
      • MI

        public static final DistanceUnit MI
        Represents the american mile unit.
      • DEGREES

        public static final DistanceUnit DEGREES
        Represents the lat long degree unit.
      • MINUTE

        public static final DistanceUnit MINUTE
        Represents the lat long minute unit.
      • SECOND

        public static final DistanceUnit SECOND
        Represents the lat long second unit.
      • PX

        public static final DistanceUnit PX
        Represents the pixel unit. The conversion factor is the one used by JasperReports (1 inch = 72 pixel).
      • PT

        public static final DistanceUnit PT
        Represents the point unit.
      • PC

        public static final DistanceUnit PC
        Represents the pica unit.
    • Method Detail

      • values

        public static DistanceUnit[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (DistanceUnit c : DistanceUnit.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static DistanceUnit valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • fromString

        public static DistanceUnit fromString​(java.lang.String val)
        Parse the value and return the identified unit object.
        Parameters:
        val - the string to parse.
        Returns:
        null if this unit is unknown
      • getBestUnit

        public static DistanceUnit getBestUnit​(double value,
                                               DistanceUnit unit)
        Return the first unit that would give a value >=1.
        Parameters:
        value - the value
        unit - the unit of the value
      • fromProjection

        public static DistanceUnit fromProjection​(org.geotools.api.referencing.crs.CoordinateReferenceSystem projection)
        Determine the unit of the given projection.
        Parameters:
        projection - the projection to determine
      • isBase

        public boolean isBase()
      • convertTo

        public double convertTo​(double value,
                                DistanceUnit targetUnit)
        Convert values in this unit to the equivalent value in another unit.
         DistanceUnit.M.convertTo(1.0, DistanceUnit.MM)==1000.0
         
        Parameters:
        value - a value in the same unit as this DistanceUnit
        targetUnit - the unit to convert value to (from this unit)
      • isSameBaseUnit

        public boolean isSameBaseUnit​(DistanceUnit target)
        Check if this unit and the target unit have the same "base" unit IE inches and feet have same base unit.
        Parameters:
        target - the unit to compare to this unit.
      • toString

        public final java.lang.String toString()
        Overrides:
        toString in class java.lang.Enum<DistanceUnit>
      • getAllUnits

        public final DistanceUnit[] getAllUnits()
        Return the sorted list (from smallest to biggest) of units sharing the same base unit.
        Returns:
        the sorted list (from smallest to biggest) of units sharing the same base unit.