# Class ImmutableDirectPosition

Object
FormattableObject
AbstractDirectPosition
ImmutableDirectPosition

All Implemented Interfaces:
  `Serializable, Printable, Position, DirectPosition`

public final class ImmutableDirectPosition extends AbstractDirectPosition implements Serializable
An immutable `DirectPosition` (the coordinates of a position) of arbitrary dimension. This final class is immutable and thus inherently thread-safe if the `CoordinateReferenceSystem` instance given to the constructor is immutable. This is usually the case in Apache SIS.

Since:
  1.6
See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ImmutableDirectPosition(CoordinateReferenceSystem crs, double... coordinates)`
  Constructs a position defined by a sequence of coordinate values.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static ImmutableDirectPosition`
  `castOrCopy(DirectPosition position)`
  Returns the given position as an `ImmutableDirectPosition` instance.
  `double`
  `getCoordinate(int dimension)`
  Returns the coordinate at the specified dimension.
  `CoordinateReferenceSystem`
  `getCoordinateReferenceSystem()`
  Returns the coordinate reference system in which the coordinates are given.
  `double[]`
  `getCoordinates()`
  Returns a sequence of numbers that hold the coordinates of this position in its reference system.
  `int`
  `getDimension()`
  The length of coordinate sequence (the number of entries).

  ### Methods inherited from class AbstractDirectPosition

  `formatTo, getCoordinate, getDirectPosition, getOrdinate, normalize, setCoordinate, setLocation, setOrdinate`

  ### Methods inherited from class FormattableObject

  `print, toString, toWKT`

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### ImmutableDirectPosition

    public ImmutableDirectPosition(CoordinateReferenceSystem crs, double... coordinates) throws MismatchedDimensionException
    Constructs a position defined by a sequence of coordinate values.
    Parameters:
      `crs` - the CRS to assign to this direct position, or `null`.
      `coordinates` - the coordinate values for each dimension.
    Throws:
      `MismatchedDimensionException` - if the CRS dimension is not equal to the number of coordinates.

- ## Method Details

  - ### castOrCopy

    public static ImmutableDirectPosition castOrCopy(DirectPosition position)
    Returns the given position as an `ImmutableDirectPosition` instance. If the given position is already an instance of `ImmutableDirectPosition`, then it is returned unchanged. Otherwise, the coordinate values and the CRS of the given position are copied in a new position.
    Parameters:
      `position` - the position to cast or copy, or `null`.
    Returns:
      the values of the given position as an `ImmutableDirectPosition` instance.

  - ### getDimension

    public int getDimension()
    The length of coordinate sequence (the number of entries).
    Specified by:
      `getDimension` in interface `DirectPosition`
    Returns:
      the dimensionality of this position.

  - ### getCoordinateReferenceSystem

    public CoordinateReferenceSystem getCoordinateReferenceSystem()
    Returns the coordinate reference system in which the coordinates are given. May be `null` if this particular `DirectPosition` is included in a larger object with such a reference to a CRS.
    Specified by:
      `getCoordinateReferenceSystem` in interface `DirectPosition`
    Overrides:
      `getCoordinateReferenceSystem` in class `AbstractDirectPosition`
    Returns:
      the coordinate reference system, or `null`.

  - ### getCoordinates

    public double[] getCoordinates()
    Returns a sequence of numbers that hold the coordinates of this position in its reference system.
    Overrides:
      `getCoordinates` in class `AbstractDirectPosition`
    Returns:
      a copy of the coordinates array.

  - ### getCoordinate

    public double getCoordinate(int dimension) throws IndexOutOfBoundsException
    Returns the coordinate at the specified dimension.
    Specified by:
      `getCoordinate` in class `AbstractDirectPosition`
    Parameters:
      `dimension` - the dimension in the range 0 to dimension-1.
    Returns:
      the coordinate at the specified dimension.
    Throws:
      `IndexOutOfBoundsException` - if the specified dimension is out of bounds.