org.ka2ddo.util
Enum DistanceUnit

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

public enum DistanceUnit
extends java.lang.Enum<DistanceUnit>
implements UnitEnumHasShortUnit<DistanceUnit>

This enumeration declares units (with conversion factors) for measuring distances.


Enum Constant Summary
DEG_LAT
          Distances in degrees of latitude upon the Earth.
FEET
          Distances in feet.
INCH
          Distances in inches.
KM
          Distances in kilometers,
METER
          Distances in meters.
MI
          Distances in statute miles.
MM
          Distances in millimeters.
NM
          Distances in nautical miles.
 
Field Summary
static float CONV_DEGLAT_TO_METERS
          Convenience constant for degrees latitude to meters when both units are fixed in equation.
static float CONV_METERS_TO_DEGLAT
          Convenience constant for meters to degrees latitude when both units are fixed in equation.
static float CONV_METERS_TO_FT
          Convenience constant for meters to feet when both units are fixed in equation.
static float CONV_METERS_TO_MI
          Convenience constant for meters to statute miles when both units are fixed in equation.
static float CONV_NM_TO_METERS
          Convenience constant for nautical miles to meters when both units are fixed in equation.
 
Method Summary
 float from(DistanceUnit other)
          Get the multiplicative conversion factor to convert a distance from the specified units to this unit.
 java.lang.String getAbbreviation()
          Get short standard abbreviation for this DistanceUnit.
 int getDepth()
          Get depth index for this unit instance's hierarchy of different-sized units.
 float getOffset(DistanceUnit other)
          Get the additive offset to convert a value from the specified unit to this unit.
 DistanceUnit getShortUnit()
          Get the shorter DistanceUnit associated with this DistanceUnit.
 java.lang.String getSpeedString()
          Get the descriptive String for a DistanceUnit when used for velocity as DistanceUnit per hour.
static DistanceUnit[] getSpeedUnits()
          Get an array of all DistanceUnits that can do speeds.
 DistanceUnit getTinyUnit()
          Get the extremely short DistanceUnit associated with this DistanceUnit.
static DistanceUnit getUnitForName(java.lang.String name)
          Convert a string representing the abbreviation for a DistanceUnit into the enum instance for that unit.
static DistanceUnit lookupSpeedUnit(java.lang.String speedUnit)
          Find the DistanceUnit whose speed has the specified unit name.
static DistanceUnit[] nonClonedValues()
          Get a non-copied array of all DistanceUnit enum values.
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, toString, valueOf
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Enum Constant Detail

MM

public static final DistanceUnit MM
Distances in millimeters.


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.

Field Detail

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.

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

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(java.lang.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 java.lang.String getSpeedString()
Get the descriptive String for a DistanceUnit when used for velocity as DistanceUnit per hour.

Returns:
speed unit String

getAbbreviation

public java.lang.String getAbbreviation()
Get short standard abbreviation for this DistanceUnit.

Returns:
abbreviation string

getUnitForName

public static DistanceUnit getUnitForName(java.lang.String name)
Convert a string representing the abbreviation 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

nonClonedValues

public static DistanceUnit[] nonClonedValues()
Get a non-copied array of all DistanceUnit enum values.

Returns:
array of DistanceUnits

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