Enum Class DistanceUnit
- All Implemented Interfaces:
Serializable,Comparable<DistanceUnit>,Constable
The DistanceUnit enumerates several units for measuring distances. These units
provide methods for converting strings and methods to convert units among each
others.The default unit used within this project is
METERS
which is defined by DEFAULT-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classNested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescription -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic doubleconvert(double distance, DistanceUnit from, DistanceUnit to) Converts the given distance from the given DistanceUnit, to the given DistanceUnitdoubleString[]getNames()static DistanceUnit.DistanceparseDistance(String distance) Parse aDistanceUnit.Distancefrom a given StringtoString()toString(double distance) Convert a value to a distance stringstatic DistanceUnitReturns the enum constant of this class with the specified name.static DistanceUnit[]values()Returns an array containing the constants of this enum class, in the order they are declared.Methods inherited from class java.lang.Enum
compareTo, describeConstable, equals, getDeclaringClass, hashCode, name, ordinal, valueOf
-
Enum Constant Details
-
INCH
-
YARD
-
FEET
-
KILOMETERS
-
NAUTICALMILES
-
MILLIMETERS
-
CENTIMETERS
-
MILES
-
METERS
-
-
Field Details
-
DEFAULT
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
getMeters
-
getNames
-
toString
Convert a value to a distance string- Parameters:
distance- value to convert- Returns:
- String representation of the distance
-
toString
- Overrides:
toStringin classEnum<DistanceUnit>
-
parseDistance
Parse aDistanceUnit.Distancefrom a given String- Parameters:
distance- String defining aDistanceUnit.Distance- Returns:
- parsed
DistanceUnit.Distance
-
convert
Converts the given distance from the given DistanceUnit, to the given DistanceUnit- Parameters:
distance- Distance to convertfrom- Unit to convert the distance fromto- Unit of distance to convert to- Returns:
- Given distance converted to the distance in the given unit
-