Package org.opengis.test.referencing
Class SimpleDirectPosition
- java.lang.Object
-
- org.opengis.test.referencing.SimpleDirectPosition
-
- All Implemented Interfaces:
Position
,DirectPosition
final class SimpleDirectPosition extends java.lang.Object implements DirectPosition
A trivial implementation ofDirectPosition
for internal usage byTransformTestCase
. Not public because strictly reserved to tests.- Since:
- 2.2
- Version:
- 3.0
-
-
Field Summary
Fields Modifier and Type Field Description protected double[]
ordinates
The ordinates.
-
Constructor Summary
Constructors Constructor Description SimpleDirectPosition(int dimension)
Creates a new direct position of the given dimension.SimpleDirectPosition(java.awt.geom.Point2D point)
Creates a new two-dimensional direct position initialized to the given point.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
equals(java.lang.Object object)
Returnstrue
if this direct position is equals to the given object.double[]
getCoordinate()
A copy of the ordinates presented as an array of double values.CoordinateReferenceSystem
getCoordinateReferenceSystem()
Returns alwaysnull
, since it is allowed by the specification andTransformTestCase
doesn't want to test the handling of CRS.double[]
getCoordinates()
Deprecated.int
getDimension()
The length of coordinate sequence (the number of entries).DirectPosition
getDirectPosition()
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.java.lang.String
toString()
Returns a string representation of this direct position.
-
-
-
Constructor Detail
-
SimpleDirectPosition
public SimpleDirectPosition(int dimension)
Creates a new direct position of the given dimension.- Parameters:
dimension
- The dimension.
-
SimpleDirectPosition
public SimpleDirectPosition(java.awt.geom.Point2D point)
Creates a new two-dimensional direct position initialized to the given point.
-
-
Method Detail
-
getCoordinateReferenceSystem
public CoordinateReferenceSystem 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 public double[] getCoordinates()
Deprecated.
-
getOrdinate
public double getOrdinate(int dimension) throws java.lang.IndexOutOfBoundsException
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:
java.lang.IndexOutOfBoundsException
- If the given index is negative or is equals or greater than the envelope dimension.
-
setOrdinate
public void setOrdinate(int dimension, double value) throws java.lang.IndexOutOfBoundsException
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:
java.lang.IndexOutOfBoundsException
- If the given index is negative or is equals or greater than the envelope dimension.
-
getDirectPosition
public DirectPosition 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
public boolean equals(java.lang.Object object)
Returnstrue
if this direct position is equals to the given object.- Specified by:
equals
in interfaceDirectPosition
- Overrides:
equals
in classjava.lang.Object
- 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 classjava.lang.Object
- Returns:
- A hash code value for this direct position.
-
toString
public java.lang.String toString()
Returns a string representation of this direct position.- Overrides:
toString
in classjava.lang.Object
-
-