org.apache.solr.util

## Class DistanceUnits

- java.lang.Object
- - org.apache.solr.util.DistanceUnits

-     public class DistanceUnits
      extends Object

  Used with a spatial field type for all distance measurements.
  See Also:
    `AbstractSpatialFieldType`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static DistanceUnits` | `DEGREES`
    `static String` | `DEGREES_PARAM`
    `static DistanceUnits` | `KILOMETERS`
    `static String` | `KILOMETERS_PARAM`
    `static DistanceUnits` | `MILES`
    `static String` | `MILES_PARAM`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `addUnits(String strId, double earthRadius, double multiplierThisToDegrees)` Custom distance units can be supplied using this method.
    `double` | `getEarthRadius()`
    `String` | `getStringIdentifier()`
    `static Set<String>` | `getSupportedUnits()`
    `double` | `multiplierFromDegreesToThisUnit()`
    `double` | `multiplierFromThisUnitToDegrees()`
    `String` | `toString()`
    `static DistanceUnits` | `valueOf(String str)` Parses a string representation of distance units and returns its implementing class instance.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### KILOMETERS_PARAM

          public static final String KILOMETERS_PARAM

      See Also:
        Constant Field Values

    - #### MILES_PARAM

          public static final String MILES_PARAM

      See Also:
        Constant Field Values

    - #### DEGREES_PARAM

          public static final String DEGREES_PARAM

      See Also:
        Constant Field Values

    - #### KILOMETERS

          public static final DistanceUnits KILOMETERS

    - #### MILES

          public static final DistanceUnits MILES

    - #### DEGREES

          public static final DistanceUnits DEGREES

  - ### Method Detail

    - #### valueOf

          public static DistanceUnits valueOf(String str)

      Parses a string representation of distance units and returns its implementing class instance. Preferred way to parse a DistanceUnits would be to use `AbstractSpatialFieldType.parseDistanceUnits(String)`, since it will default to one defined on the field type if the string is null.
      Parameters:
        `str` - String representation of distance units, e.g. "kilometers", "miles" etc. (null ok)
      Returns:
        an instance of the concrete DistanceUnits, null if not found.

    - #### getSupportedUnits

          public static Set<String> getSupportedUnits()

    - #### getEarthRadius

          public double getEarthRadius()

      Returns:
        Radius of the earth in this distance units

    - #### multiplierFromThisUnitToDegrees

          public double multiplierFromThisUnitToDegrees()

      Returns:
        multiplier needed to convert a distance in current units to degrees

    - #### multiplierFromDegreesToThisUnit

          public double multiplierFromDegreesToThisUnit()

      Returns:
        multiplier needed to convert a distance in degrees to current units

    - #### getStringIdentifier

          public String getStringIdentifier()

      Returns:
        the string identifier associated with this units instance

    - #### addUnits

          public static void addUnits(String strId,
                                      double earthRadius,
                                      double multiplierThisToDegrees)

      Custom distance units can be supplied using this method. It's thread-safe.
      Parameters:
        `strId` - string identifier for the units
        `earthRadius` - radius of earth in supplied units
        `multiplierThisToDegrees` - multiplier to convert to degrees

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

Copyright © 2000-2016 Apache Software Foundation. All Rights Reserved.