Enum DistanceUnit

    • 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​(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:
        IllegalArgumentException - if this enum type has no constant with the specified name
        NullPointerException - if the argument is null
      • getEarthCircumference

        public double getEarthCircumference()
        Measures the circumference of earth in this unit
        Returns:
        length of earth circumference in this unit
      • getEarthRadius

        public double getEarthRadius()
        Measures the radius of earth in this unit
        Returns:
        length of earth radius in this unit
      • getDistancePerDegree

        public double getDistancePerDegree()
        Measures a longitude in this unit
        Returns:
        length of a longitude degree in this unit
      • toMeters

        public double toMeters​(double distance)
        Convert a value into meters
        Parameters:
        distance - distance in this unit
        Returns:
        value in meters
      • fromMeters

        public double fromMeters​(double distance)
        Convert a value given in meters to a value of this unit
        Parameters:
        distance - distance in meters
        Returns:
        value in this unit
      • convert

        public double convert​(double distance,
                              DistanceUnit unit)
        Convert a given value into another unit
        Parameters:
        distance - value in this unit
        unit - source unit
        Returns:
        value in this unit
      • toString

        public String toString​(double distance)
        Convert a value to a distance string
        Parameters:
        distance - value to convert
        Returns:
        String representation of the distance
      • convert

        public static double convert​(double distance,
                                     DistanceUnit from,
                                     DistanceUnit to)
        Converts the given distance from the given DistanceUnit, to the given DistanceUnit
        Parameters:
        distance - Distance to convert
        from - Unit to convert the distance from
        to - Unit of distance to convert to
        Returns:
        Given distance converted to the distance in the given unit
      • parse

        public static double parse​(String distance,
                                   DistanceUnit defaultUnit,
                                   DistanceUnit to)
        Parses a given distance and converts it to the specified unit.
        Parameters:
        distance - String defining a distance (value and unit)
        defaultUnit - unit assumed if none is defined
        to - unit of result
        Returns:
        parsed distance
      • parse

        public double parse​(String distance,
                            DistanceUnit defaultUnit)
        Parses a given distance and converts it to this unit.
        Parameters:
        distance - String defining a distance (value and unit)
        defaultUnit - unit to expect if none if provided
        Returns:
        parsed distance
      • parseUnit

        public static DistanceUnit parseUnit​(String distance,
                                             DistanceUnit defaultUnit)
        Parses the suffix of a given distance string and return the corresponding DistanceUnit
        Parameters:
        distance - string representing a distance
        defaultUnit - default unit to use, if no unit is provided by the string
        Returns:
        unit of the given distance