org.springframework.data.geo

## Class Distance

- java.lang.Object
- - org.springframework.data.geo.Distance

All Implemented Interfaces:
  Serializable, Comparable<Distance>

    public final class Distance
    extends Object
    implements Serializable, Comparable<Distance>

Value object to represent distances in a given metric.

Since:
  1.8
Author:
  Oliver Gierke, Thomas Darimont
See Also:
  Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`Distance(double value)` Creates a new `Distance` with a neutral metric.
`Distance(double value, Metric metric)` Creates a new `Distance` with the given `Metric`.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`Distance` `add(Distance other)` Adds the given distance to the current one.
`Distance` `add(Distance other, Metric metric)` Adds the given `Distance` to the current one and forces the result to be in a given `Metric`.
`static Range<Distance>` `between(Distance min, Distance max)` Creates a `Range` between the given `Distance`.
`static Range<Distance>` `between(double minValue, Metric minMetric, double maxValue, Metric maxMetric)` Creates a new `Range` by creating minimum and maximum `Distance` from the given values.
`int` `compareTo(Distance that)`
`boolean` `equals(Object o)`
`Metric` `getMetric()`
`double` `getNormalizedValue()` Returns the normalized value regarding the underlying `Metric`.
`String` `getUnit()` Returns a `String` representation of the unit the distance is in.
`double` `getValue()`
`int` `hashCode()`
`Distance` `in(Metric metric)` Returns a new `Distance` in the given `Metric`.
`String` `toString()`

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

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

### Constructor Detail

#### Distance

    public Distance(double value)

Creates a new `Distance` with a neutral metric. This means the provided value needs to be in normalized form.

Parameters:
  `value` -

#### Distance

    public Distance(double value,
                    Metric metric)

Creates a new `Distance` with the given `Metric`.

Parameters:
  `value` -
  `metric` - must not be null.

### Method Detail

#### between

    public static Range<Distance> between(Distance min,
                                          Distance max)

Creates a `Range` between the given `Distance`.

Parameters:
  `min` - can be null.
  `max` - can be null.
Returns:
  will never be null.

#### between

    public static Range<Distance> between(double minValue,
                                          Metric minMetric,
                                          double maxValue,
                                          Metric maxMetric)

Creates a new `Range` by creating minimum and maximum `Distance` from the given values.

Parameters:
  `minValue` -
  `minMetric` - can be null.
  `maxValue` -
  `maxMetric` - can be null.
Returns:

#### getNormalizedValue

    public double getNormalizedValue()

Returns the normalized value regarding the underlying `Metric`.

Returns:

#### getUnit

    public String getUnit()

Returns a `String` representation of the unit the distance is in.

Returns:
  the unit
See Also:
  `Metric.getAbbreviation()`

#### add

    public Distance add(Distance other)

Adds the given distance to the current one. The resulting `Distance` will be in the same metric as the current one.

Parameters:
  `other` - must not be null.
Returns:

#### add

    public Distance add(Distance other,
                        Metric metric)

Adds the given `Distance` to the current one and forces the result to be in a given `Metric`.

Parameters:
  `other` - must not be null.
  `metric` - must not be null.
Returns:

#### in

    public Distance in(Metric metric)

Returns a new `Distance` in the given `Metric`. This means that the returned instance will have the same normalized value as the original instance.

Parameters:
  `metric` - must not be null.
Returns:

#### compareTo

    public int compareTo(@Nullable
                         Distance that)

Specified by:
  `compareTo` in interface `Comparable<Distance>`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`

#### getValue

    public double getValue()

#### getMetric

    public Metric getMetric()

#### equals

    public boolean equals(Object o)

Overrides:
  `equals` in class `Object`

#### hashCode

    public int hashCode()

Overrides:
  `hashCode` in class `Object`