Class SimpleDirectPosition

java.lang.Object
org.opengis.test.referencing.SimpleDirectPosition
All Implemented Interfaces:
Position, DirectPosition

final class SimpleDirectPosition extends Object implements 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 Details

    • ordinates

      protected final double[] ordinates
      The ordinates.
  • Constructor Details

    • SimpleDirectPosition

      public SimpleDirectPosition(int dimension)
      Creates a new direct position of the given dimension.
      Parameters:
      dimension - The dimension.
    • SimpleDirectPosition

      public SimpleDirectPosition(Point2D point)
      Creates a new two-dimensional direct position initialized to the given point.
  • Method Details

    • getCoordinateReferenceSystem

      public CoordinateReferenceSystem getCoordinateReferenceSystem()
      Returns always null, since it is allowed by the specification and TransformTestCase doesn't want to test the handling of CRS.
      Specified by:
      getCoordinateReferenceSystem in interface DirectPosition
      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 interface DirectPosition
      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.
       final int dim = position.getDimension();
       for (int i=0; i<dim; i++) {
           position.getOrdinate(i); // no copy overhead
       }
       
      To manipulate ordinates, the following idiom can be used:
       position.setOrdinate(i, value); // edit in place
       
      There are a couple reasons for requerying a copy:

      • 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 future DirectPosition 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 of DirectPosition.getOrdinate(int).

      Specified by:
      getCoordinate in interface DirectPosition
      Returns:
      A copy of the coordinates. Changes in the returned array will not be reflected back in this DirectPosition object.
    • getCoordinates

      @Deprecated public double[] getCoordinates()
      Deprecated.
    • getOrdinate

      public double getOrdinate(int dimension) throws IndexOutOfBoundsException
      Returns the ordinate at the specified dimension.
      Specified by:
      getOrdinate in interface DirectPosition
      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

      public void setOrdinate(int dimension, double value) throws IndexOutOfBoundsException
      Sets the ordinate value along the specified dimension.
      Specified by:
      setOrdinate in interface DirectPosition
      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

      public DirectPosition getDirectPosition()
      Returns the direct position. This method shall never returns null, but may returns this if invoked on an object which is already a DirectPosition instance.
      Specified by:
      getDirectPosition in interface Position
      Returns:
      The direct position (may be this).
    • equals

      public boolean equals(Object object)
      Returns true if this direct position is equals to the given object.
      Specified by:
      equals in interface DirectPosition
      Overrides:
      equals in class 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 interface DirectPosition
      Overrides:
      hashCode in class Object
      Returns:
      A hash code value for this direct position.
    • toString

      public String toString()
      Returns a string representation of this direct position.
      Overrides:
      toString in class Object