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 class
static class
Nested 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 double
convert
(double distance, DistanceUnit from, DistanceUnit to) Converts the given distance from the given DistanceUnit, to the given DistanceUnitdouble
String[]
getNames()
static DistanceUnit.Distance
parseDistance
(String distance) Parse aDistanceUnit.Distance
from a given StringtoString()
toString
(double distance) Convert a value to a distance stringstatic DistanceUnit
Returns 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:
toString
in classEnum<DistanceUnit>
-
parseDistance
Parse aDistanceUnit.Distance
from 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
-