com.mapinfo.midev.unit

## Class Offset

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

All Implemented Interfaces:
  Serializable

    public final class Offset
    extends Object
    implements Serializable

Class that represents the value, and unit of a distance measure.

See Also:
  Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`Offset(double value, LinearUnit unit)` Create Offset object.

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static Offset` `convert(Offset offset, LinearUnit unit)` Returns the specified Offset converted from its LinearUnit to the specified LinearUnit.
`boolean` `equals(Object o)` Equals implementation.
`boolean` `equivalent(Offset offset)` Is this offset equivalent to the given offset.
`boolean` `equivalent(Offset offset, double tolerance)` Is this offset equivalent to the given offset within the given tolerance.
`LinearUnit` `getUnit()` Get the unit of measure for this offset.
`double` `getValue()` Get the value of measure for this offset.
`double` `getValue(LinearUnit unit)` Return the offset in the requested unit, converting if necessary.
`int` `hashCode()` Hashcode implementation.

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

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

### Constructor Detail

#### Offset

    public Offset(double value,
                  LinearUnit unit)

Create Offset object.

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

### Method Detail

#### getUnit

    public LinearUnit getUnit()

Get the unit of measure for this offset.

Returns:
  The unit of measure for this offset.

#### getValue

    public double getValue()

Get the value of measure for this offset. The unit of this value is the unit returned by `Offset.getUnit()`.

Returns:
  The value of measure for this offset.

#### getValue

    public double getValue(LinearUnit unit)

Return the offset in the requested unit, converting if necessary.

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

#### equivalent

    public boolean equivalent(Offset offset)

Is this offset equivalent to the given offset.

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

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

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

#### equivalent

    public boolean equivalent(Offset offset,
                              double tolerance)

Is this offset equivalent to the given offset within the given tolerance.

Parameters:
  `offset` - offset to test for equivalence.
  `tolerance` - the tolerance value to test with. Specified in meters.
Returns:
  true if equivalent within tolerance, false otherwise.

#### 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 Offset convert(Offset offset,
                                 LinearUnit unit)

Returns the specified Offset converted from its LinearUnit to the specified LinearUnit. If the LinearUnit of the specified Offset is the same as the specified LinearUnit to convert to then the specified offset is returned.

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