Package org.opengis.test.referencing
Class SimpleDirectPosition
java.lang.Object
org.opengis.test.referencing.SimpleDirectPosition
- All Implemented Interfaces:
Position
,DirectPosition
A trivial implementation of
DirectPosition
for internal usage by
TransformTestCase
. Not public because strictly reserved to tests.- Since:
- 2.2
- Version:
- 3.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionSimpleDirectPosition
(int dimension) Creates a new direct position of the given dimension.SimpleDirectPosition
(Point2D point) Creates a new two-dimensional direct position initialized to the given point. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Returnstrue
if this direct position is equals to the given object.double[]
A copy of the ordinates presented as an array of double values.Returns alwaysnull
, since it is allowed by the specification andTransformTestCase
doesn't want to test the handling of CRS.double[]
Deprecated.int
The length of coordinate sequence (the number of entries).Returns the direct position.double
getOrdinate
(int dimension) Returns the ordinate at the specified dimension.int
hashCode()
Returns a hash code value for this direct position.void
setOrdinate
(int dimension, double value) Sets the ordinate value along the specified dimension.toString()
Returns a string representation of this direct position.
-
Field Details
-
ordinates
protected final double[] ordinatesThe ordinates.
-
-
Constructor Details
-
SimpleDirectPosition
public SimpleDirectPosition(int dimension) Creates a new direct position of the given dimension.- Parameters:
dimension
- The dimension.
-
SimpleDirectPosition
Creates a new two-dimensional direct position initialized to the given point.
-
-
Method Details
-
getCoordinateReferenceSystem
Returns alwaysnull
, since it is allowed by the specification andTransformTestCase
doesn't want to test the handling of CRS.- Specified by:
getCoordinateReferenceSystem
in interfaceDirectPosition
- Returns:
- The coordinate reference system, or
null
.
-
getDimension
public int getDimension()The length of coordinate sequence (the number of entries). This is determined by the coordinate reference system.- Specified by:
getDimension
in interfaceDirectPosition
- Returns:
- The dimensionality of this position.
-
getCoordinate
public double[] getCoordinate()A copy of the ordinates presented as an array of double values. Please note that this is only a copy (the real values may be stored in another format) so changes to the returned array will not affect the source DirectPosition.
To manipulate ordinates, the following idiom can be used:final int dim = position.getDimension(); for (int i=0; i<dim; i++) { position.getOrdinate(i); // no copy overhead }
There are a couple reasons for requerying a copy:position.setOrdinate(i, value); // edit in place
- We want an array of coordinates with the intend to modify it for computation purpose
(without modifying the original
DirectPosition
), or we want to protect the array from futureDirectPosition
changes. - If
DirectPosition.getOrdinates()
is guaranteed to not return the backing array, then we can work directly on this array. If we don't have this guarantee, then we must conservatively clone the array in every cases. - Cloning the returned array is useless if the implementation cloned the array or was forced to returns a new array anyway (for example because the coordinates were computed on the fly)
Precedence is given to data integrity over
getOrdinates()
performance. Performance concern can be avoided with usage ofDirectPosition.getOrdinate(int)
.- Specified by:
getCoordinate
in interfaceDirectPosition
- Returns:
- A copy of the coordinates. Changes in the returned array will not be reflected back
in this
DirectPosition
object.
- We want an array of coordinates with the intend to modify it for computation purpose
(without modifying the original
-
getCoordinates
Deprecated. -
getOrdinate
Returns the ordinate at the specified dimension.- Specified by:
getOrdinate
in interfaceDirectPosition
- Parameters:
dimension
- The dimension in the range 0 to dimension-1.- Returns:
- The coordinate at the specified dimension.
- Throws:
IndexOutOfBoundsException
- If the given index is negative or is equals or greater than the envelope dimension.
-
setOrdinate
Sets the ordinate value along the specified dimension.- Specified by:
setOrdinate
in interfaceDirectPosition
- Parameters:
dimension
- the dimension for the ordinate of interest.value
- the ordinate value of interest.- Throws:
IndexOutOfBoundsException
- If the given index is negative or is equals or greater than the envelope dimension.
-
getDirectPosition
Returns the direct position. This method shall never returnsnull
, but may returnsthis
if invoked on an object which is already aDirectPosition
instance.- Specified by:
getDirectPosition
in interfacePosition
- Returns:
- The direct position (may be
this
).
-
equals
Returnstrue
if this direct position is equals to the given object.- Specified by:
equals
in interfaceDirectPosition
- Overrides:
equals
in classObject
- Parameters:
object
- The object to compare with this direct position for equality.- Returns:
true
if the given object is equals to this direct position.
-
hashCode
public int hashCode()Returns a hash code value for this direct position.- Specified by:
hashCode
in interfaceDirectPosition
- Overrides:
hashCode
in classObject
- Returns:
- A hash code value for this direct position.
-
toString
Returns a string representation of this direct position.
-