com.mapinfo.midev.unit

## Class Length

- java.lang.Object
- - com.mapinfo.midev.unit.Length

All Implemented Interfaces:
  Serializable, Comparable

    public final class Length
    extends Object
    implements Serializable, Comparable

Represents a length which is defined as a scalar number paired with a `LinearUnit`.

See Also:
  Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`Length(double value, LinearUnit unit)` Create a `Length` object with `ComputationType.SPHERICAL` computation type.
`Length(double value, LinearUnit unit, ComputationType ct)` Create a `Length` object with the specified `ComputationType` computation type.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`int` `compareTo(Length length)` Compare this legnth to another.
`static Angle` `convert(Length length)` Returns the specified `Length` into an comparable `Angle`.
`static Length` `convert(Length length, LinearUnit unit)` Returns the specified `Length` converted from its `LinearUnit` to the specified `LinearUnit`.
`boolean` `equals(Object o)` Equals implementation.
`boolean` `equivalent(Length length)` Returns `true` if the specified `Length` is equivalent to this `Length`.
`boolean` `equivalent(Length length, double tolerance)` Returns `true` if the specified `Length` is equivalent to this `Length`.
`ComputationType` `getComputationType()` Returns the computation type used to interpret geometry coordinates when doing the length computations.
`LinearUnit` `getUnit()` Returns the unit of measure for this length.
`double` `getValue()` Returns the value of measure for this length.
`double` `getValue(LinearUnit unit)` Returns the length in the requested unit, converting if necessary.
`int` `hashCode()` Hashcode implementation.
`String` `toString()`

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

`getClass, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### Length

    public Length(double value,
                  LinearUnit unit)

Create a `Length` object with `ComputationType.SPHERICAL` computation type.

Parameters:
  `value` - the value of measure for this length.
  `unit` - the unit of measure for this length.
Throws:
  `IllegalArgumentException` - if the specified unit is null.

#### Length

    public Length(double value,
                  LinearUnit unit,
                  ComputationType ct)

Create a `Length` object with the specified `ComputationType` computation type.

Parameters:
  `value` - the value of measure for this length.
  `unit` - the unit of measure for this length.
Throws:
  `IllegalArgumentException` - if the specified unit is null.

### Method Detail

#### getUnit

    public LinearUnit getUnit()

Returns the unit of measure for this length.

Returns:
  The unit of measure for this length.

#### getValue

    public double getValue()

Returns the value of measure for this length.

Returns:
  The value of measure for this length.

#### getComputationType

    public ComputationType getComputationType()

Returns the computation type used to interpret geometry coordinates when doing the length computations.

Returns:
  The computation type for this length.

#### getValue

    public double getValue(LinearUnit unit)

Returns the length in the requested unit, converting if necessary.

Parameters:
  `unit` - the desired unit.
Returns:
  the value of the length in the specified unit.
Throws:
  `IllegalArgumentException` - if the specified unit is null.

#### equivalent

    public boolean equivalent(Length length)

Returns `true` if the specified `Length` is equivalent to this `Length`. Same as calling `Length.equivalent(Length, double)`.

Parameters:
  `length` - length to test for equivalence.
Returns:
  true if equivalent, false otherwise.

#### equivalent

    public boolean equivalent(Length length,
                              double tolerance)

Returns `true` if the specified `Length` is equivalent to this `Length`.

Two `Length`s are equivalent if they represent the same absolute distance, e.g. Length 1000 meters is equivalent to `Length` 1 kilometer.

This method has the same behavior as calling `Length.equivalent(Length,double)` with tolerance == 0;

Parameters:
  `length` - length to test for equivalence.
Returns:
  true if equivalent, false otherwise.

#### convert

    public static Angle convert(Length length)

Returns the specified `Length` into an comparable `Angle`.

Note: this method treats the input length as a measure along a Great Circle of the earth and uses the conversion constant:

1 Great Circle degree = 111194.87428 meter

The meaning of the input length determines whether this conversion produces a reasonable result.

Parameters:
  `length` - an length
Returns:
  input length converted to an angle using the described conversion assumptions.

#### equals

    public boolean equals(Object o)

Equals implementation.

Overrides:
  `equals` in class `Object`
Parameters:
  `o` - The object to test for equality.
Returns:
  TRUE if this object equals the parameter object.

#### hashCode

    public int hashCode()

Hashcode implementation.

Overrides:
  `hashCode` in class `Object`
Returns:
  The hashCode for this object.

#### convert

    public static Length convert(Length length,
                                 LinearUnit unit)

Returns the specified `Length` converted from its `LinearUnit` to the specified `LinearUnit`. If the `LinearUnit` of the specified `Length` is the same as the specified `LinearUnit` to convert to then the specified length is returned.

Parameters:
  `length` - The `Length` to convert.
  `unit` - The unit to convert the specified Length to.
Returns:
  the specified Length converted from its LinearUnit to the specified LinearUnit.

#### compareTo

    public int compareTo(Length length)

Compare this legnth to another. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Specified by:
  `compareTo` in interface `Comparable`

#### toString

    public String toString()

Overrides:
  `toString` in class `Object`