Enum Class DistanceUnit

java.lang.Object
java.lang.Enum<DistanceUnit>
org.ka2ddo.util.DistanceUnit
All Implemented Interfaces:
Serializable, Comparable<DistanceUnit>, Constable, UnitEnum<DistanceUnit>, UnitEnumHasShortUnit<DistanceUnit>

public enum DistanceUnit extends Enum<DistanceUnit> implements UnitEnumHasShortUnit<DistanceUnit>
This enumeration declares units (with conversion factors) for measuring distances.
Author:
Andrew Pavlin, KA2DDO
  • Nested Class Summary

    Nested classes/interfaces inherited from class java.lang.Enum

    Enum.EnumDesc<E extends Enum<E>>
  • Enum Constant Summary

    Enum Constants
    Enum Constant
    Description
    Distances in centimeters.
    Distances in degrees of latitude upon the Earth.
    Distances in feet.
    Distances in inches.
    Distances in kilometers,
    Distances in meters.
    Distances in statute miles.
    Distances in millimeters.
    Distances in nautical miles.
    Distances (heights) in building floors or stories.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float
    Convenience constant for degrees latitude to meters when both units are fixed in equation.
    static final float
    Convenience constant for meters to degrees latitude when both units are fixed in equation.
    static final float
    Convenience constant for meters to feet when both units are fixed in equation.
    static final float
    Convenience constant for meters to statute miles when both units are fixed in equation.
    static final float
    Convenience constant for nautical miles to meters when both units are fixed in equation.
    static final float
    Convenience constant for nautical miles to statute miles.
  • Method Summary

    Modifier and Type
    Method
    Description
    final float
    Get the multiplicative conversion factor to convert a distance from the specified units to this unit.
    Get short standard abbreviations for this DistanceUnit.
    int
    Get depth index for this unit instance's hierarchy of different-sized units.
    float
    Get the additive offset to convert a value from the specified unit to this unit.
    Get the shorter DistanceUnit associated with this DistanceUnit.
    Get the descriptive String for a DistanceUnit when used for velocity as DistanceUnit per hour.
    static DistanceUnit[]
    Get an array of all DistanceUnits that can do speeds.
    Get the extremely short DistanceUnit associated with this DistanceUnit.
    Convert a string representing the abbreviations for a DistanceUnit into the enum instance for that unit.
    Find the DistanceUnit whose speed has the specified unit name.
    Returns the enum constant of this class with the specified name.
    static DistanceUnit[]
    Returns an array containing the constants of this enum class, in the order they are declared.

    Methods inherited from class java.lang.Object

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

    • MM

      public static final DistanceUnit MM
      Distances in millimeters.
    • CM

      public static final DistanceUnit CM
      Distances in centimeters.
    • INCH

      public static final DistanceUnit INCH
      Distances in inches.
    • METER

      public static final DistanceUnit METER
      Distances in meters.
    • FEET

      public static final DistanceUnit FEET
      Distances in feet.
    • KM

      public static final DistanceUnit KM
      Distances in kilometers,
    • MI

      public static final DistanceUnit MI
      Distances in statute miles.
    • NM

      public static final DistanceUnit NM
      Distances in nautical miles.
    • DEG_LAT

      public static final DistanceUnit DEG_LAT
      Distances in degrees of latitude upon the Earth.
    • STORIES

      public static final DistanceUnit STORIES
      Distances (heights) in building floors or stories.
  • Field Details

    • CONV_DEGLAT_TO_METERS

      public static final float CONV_DEGLAT_TO_METERS
      Convenience constant for degrees latitude to meters when both units are fixed in equation.
    • CONV_METERS_TO_DEGLAT

      public static final float CONV_METERS_TO_DEGLAT
      Convenience constant for meters to degrees latitude when both units are fixed in equation.
    • CONV_NM_TO_METERS

      public static final float CONV_NM_TO_METERS
      Convenience constant for nautical miles to meters when both units are fixed in equation.
    • CONV_METERS_TO_MI

      public static final float CONV_METERS_TO_MI
      Convenience constant for meters to statute miles when both units are fixed in equation.
    • CONV_METERS_TO_FT

      public static final float CONV_METERS_TO_FT
      Convenience constant for meters to feet when both units are fixed in equation.
    • CONV_NM_TO_MI

      public static final float CONV_NM_TO_MI
      Convenience constant for nautical miles to statute miles.
  • Method Details

    • values

      public static DistanceUnit[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static DistanceUnit valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (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:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • from

      public final float from(DistanceUnit other)
      Get the multiplicative conversion factor to convert a distance from the specified units to this unit.
      Specified by:
      from in interface UnitEnum<DistanceUnit>
      Parameters:
      other - another DistanceUnit representing the existing units of a distance value
      Returns:
      the conversion factor to change a distance value into this unit
    • getOffset

      public float getOffset(DistanceUnit other)
      Get the additive offset to convert a value from the specified unit to this unit.
      Specified by:
      getOffset in interface UnitEnum<DistanceUnit>
      Parameters:
      other - another DistanceUnit representing the existing units of a value
      Returns:
      the offset (after multiplying by the from() factor) to add to get the value in this unit
    • getShortUnit

      public final DistanceUnit getShortUnit()
      Get the shorter DistanceUnit associated with this DistanceUnit.
      Specified by:
      getShortUnit in interface UnitEnumHasShortUnit<DistanceUnit>
      Returns:
      shorter DistanceUnit in same system of measurement
    • getTinyUnit

      public final DistanceUnit getTinyUnit()
      Get the extremely short DistanceUnit associated with this DistanceUnit.
      Returns:
      much shorter DistanceUnit in same system of measurement, or null if no such unit
    • lookupSpeedUnit

      public static DistanceUnit lookupSpeedUnit(String speedUnit)
      Find the DistanceUnit whose speed has the specified unit name.
      Parameters:
      speedUnit - String of speed unit, such as "mph", "kph", etc.
      Returns:
      DistanceUnit for this speed string, or null if no match
    • getSpeedString

      public String getSpeedString()
      Get the descriptive String for a DistanceUnit when used for velocity as DistanceUnit per hour.
      Returns:
      speed unit String
    • getAbbreviation

      public String getAbbreviation()
      Get short standard abbreviations for this DistanceUnit.
      Returns:
      abbreviations string
    • getUnitForName

      public static DistanceUnit getUnitForName(String name)
      Convert a string representing the abbreviations for a DistanceUnit into the enum instance for that unit.
      Parameters:
      name - String to be translated into a DistanceUnit
      Returns:
      corresponding DistanceUnit, or null if no match found
    • getSpeedUnits

      public static DistanceUnit[] getSpeedUnits()
      Get an array of all DistanceUnits that can do speeds.
      Returns:
      array of DistanceUnits
    • getDepth

      public int getDepth()
      Get depth index for this unit instance's hierarchy of different-sized units.
      Specified by:
      getDepth in interface UnitEnumHasShortUnit<DistanceUnit>
      Returns:
      zero-based index of how many times you can get a shorter unit before you reach the smallest unit