uk.ac.leeds.ccg.andyt.grids.core
Class Grid2DSquareCellAbstract

java.lang.Object
  extended by uk.ac.leeds.ccg.andyt.grids.utilities.ErrorHandler
      extended by uk.ac.leeds.ccg.andyt.grids.core.Grid2DSquareCellAbstract
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
Grid2DSquareCellDouble, Grid2DSquareCellInt

public abstract class Grid2DSquareCellAbstract
extends ErrorHandler
implements java.io.Serializable

Grid2DSquareCellAbstract provides inner classes for CellID and ChunkID referencing and general geometry methods for extended classes. It also controls what methods extended classes must implement and so acts somewhat like an interface. The basic geometries are ordered in set numbers of rows and columns and are arranged sequentially as their base two-dimensional orthogonal coordinate axes. The sequential arrangement goes along the x-axis row by row from the y-axis, then up the y-axis taking each row in turn. TODO: Add a constant int TYPE which can be used to switch between different types of this. Handling for NumberFormatExceptions and ArithmeticExceptions in calculations

See Also:
Serialized Form

Nested Class Summary
static class Grid2DSquareCellAbstract.CellID
          A simple CellID class for distinguishing cells.
static class Grid2DSquareCellAbstract.ChunkID
          A simple ChunkID class for distinguishing s in this chunk.
 
Field Summary
protected  int chunkNcols
          For storing the (usual) number of cells in a chunk column.
protected  int chunkNrows
          For storing the (usual) number of cells in a chunk row.
protected  java.math.BigDecimal[] dimensions
          For storing cellsize, minx, miny, maxx, maxy Although maxx and maxy could be easily calculated if required, for convenience they are calculated by default during grid construction.
protected  int dimensionsScale
          For storing the minimum number of decimal places needed to store the dimensions.
protected  java.io.File directory
          Local directory used for caching.
protected  java.util.HashMap grid2DSquareCellChunks
          The chunks that make up this instance.
protected  GridStatisticsAbstract gridStatistics
          A reference to the grid Statistics Object.
protected  java.lang.String name
          For storing the name of the grid.
protected  int nChunkCols
          For storing the number of chunk columns.
protected  int nChunkRows
          For storing the number of chunk rows.
protected  long ncols
          For storing the number of columns in the grid.
protected  long nrows
          For storing the number of rows in the grid.
protected static UnsignedLongPowersOf2 unsignedLongPowersOf2
          For storing values mapped to a binary encoded long.
 
Fields inherited from class uk.ac.leeds.ccg.andyt.grids.utilities.ErrorHandler
handleOutOfMemoryErrorFalse, handleOutOfMemoryErrorTrue, memoryReserve
 
Constructor Summary
Grid2DSquareCellAbstract()
           
 
Method Summary
 void cache(boolean cacheChunks, boolean reinitialiseMemoryReserve)
          A method to cache this instance by writing it out to an ObjectOutputStream File called Cache to be located in the File (directory) returned by getDirectory().
 void cacheAndClearChunks(boolean reinitialiseMemoryReserve)
          Caches a seriailsed version of all grid2DSquareCellChunks and clears them.
 Grid2DSquareCellAbstract.ChunkID cacheChunk(boolean reinitialiseMemoryReserve)
          Attempts to cache a seriailized version of a Chunk.
 boolean cacheChunk(Grid2DSquareCellAbstract.ChunkID chunkID, boolean reinitialiseMemoryReserve)
          Caches a seriailsed version of Chunk with given chunkID.
 boolean cacheChunk(int chunkRowIndex, int chunkColIndex, boolean reinitialiseMemoryReserve)
          Attempts to cache a seriailized version of Chunk given by; chunk row index chunkRowIndex, chunk column index chunkColIndex.
 Grid2DSquareCellAbstract.ChunkID cacheChunkExcept(Grid2DSquareCellAbstract.ChunkID chunkID, boolean reinitialiseMemoryReserve)
          Caches a Grid2DSquareCellChunk of grid2DSquareCellChunks (other that with ChunkID chunkID) then returns its ChunkID.
 Grid2DSquareCellAbstract.ChunkID cacheChunkExcept(int chunkRowIndex, int chunkColIndex, boolean reinitialiseMemoryReserve)
          Caches a Grid2DSquareCellChunk of grid2DSquareCellChunks (other that with; chunk row index chunkRowIndex, chunk column index chunkColIndex) then returns its ChunkID.
 Grid2DSquareCellAbstract.ChunkID cacheChunkExceptReverseOrder(Grid2DSquareCellAbstract.ChunkID chunkID, boolean reinitialiseMemoryReserve)
          Caches a Grid2DSquareCellChunk of grid2DSquareCellChunks (other that with ChunkID chunkID) then returns its ChunkID.
 Grid2DSquareCellAbstract.ChunkID cacheChunkExceptReverseOrder(int chunkRowIndex, int chunkColIndex, boolean reinitialiseMemoryReserve)
          Caches a Grid2DSquareCellChunk of grid2DSquareCellChunks (other that with ChunkID chunkID) then returns its ChunkID.
 void cacheChunks(boolean reinitialiseMemoryReserve)
          Caches a seriailsed version of all grid2DSquareCellChunks.
 void cacheChunks(java.util.HashSet chunkIDs, boolean reinitialiseMemoryReserve)
          Caches a seriailsed version of all grid2DSquareCellChunks in grid2DSquareCellChunkIDs.
 void cacheChunksExcept(Grid2DSquareCellAbstract.ChunkID chunkID, boolean reinitialiseMemoryReserve)
          Caches all grid2DSquareCellChunks other that with ChunkID chunkID.
 void cacheChunksExcept(java.util.HashSet chunkIDs, boolean reinitialiseMemoryReserve)
          Caches all grid2DSquareCellChunks other than those with ChunkIDs in chunkIDs.
 void clearChunk(Grid2DSquareCellAbstract.ChunkID chunkID)
          For releasing a grid2DSquareCellChunk stored in memory.
 void clearChunk(int chunkRowIndex, int chunkColIndex, boolean reinitialiseMemoryReserve)
          For releasing a grid2DSquareCellChunk stored in memory.
 void clearChunkExcept(Grid2DSquareCellAbstract.ChunkID chunkID, boolean reinitialiseMemoryReserve)
          For releasing a grid2DSquareCellChunk stored in memory except that with ChunkID given by chunkID.
 void clearChunks(boolean reinitialiseMemoryReserve)
          For releasing all grid2DSquareCellChunk stored in memory.
 void clearChunks(java.util.HashSet chunkIDs, boolean reinitialiseMemoryReserve)
          Clears Grid2DSquareCellChunkAbstracts with ChunkIDs in chunkIDs.
 void clearChunksExcept(Grid2DSquareCellAbstract.ChunkID chunkID, boolean reinitialiseMemoryReserve)
          For releasing all grid2DSquareCellChunk stored in memory except that with ChunkID given by chunkID.
 void clearChunksExcept(java.util.HashSet chunkIDs, boolean reinitialiseMemoryReserve)
          For releasing all grid2DSquareCellChunk stored in memory except those with ChunkIDs in chunkIDs.
 double[] getCellBoundsDoubleArray(double x, double y, boolean handleOutOfMemoryError)
          Returns double[] where; double[0] xmin, left most x-coordinate of cell that intersects point at (x,y) double[1] ymin, lowest y-coordinate of cell that intersects point at (x,y) double[2] xmax, right most x-coordinate of cell that intersects point at (x,y) double[3] ymax, highest y-coordinate of cell that intersects point at (x,y)
 double[] getCellBoundsDoubleArray(long cellRowIndex, long cellColIndex, boolean handleOutOfMemoryError)
          Returns double[] where; double[0] xmin, left most x-coordinate of cell at (rowIndex,colIndex) double[1] ymin, lowest y-coordinate of cell at (rowIndex,colIndex) double[2] xmax, right most x-coordinate of cell at (rowIndex,colIndex) double[3] ymax, highest y-coordinate of cell at (rowIndex,colIndex)
 long getCellColIndex(java.math.BigDecimal xBigDecimal, boolean handleOutOfMemoryError)
          Returns the cell column Index for the cells that intersect the x-coordinate x.
 long getCellColIndex(double x, boolean handleOutOfMemoryError)
          Returns the cell column Index for the cells that intersect the x-coordinate x.
 double getCellDouble(Grid2DSquareCellChunkAbstract grid2DSquareCellChunk, int chunkRowIndex, int chunkColIndex, int chunkCellRowIndex, int chunkCellColIndex, boolean handleOutOfMemoryError)
          Returns the value at chunkRowIndex, chunkColIndex, chunkCellRowIndex, chunkCellColIndex as a double.
 double getCellDouble(int chunkRowIndex, int chunkColIndex, int chunkCellRowIndex, int chunkCellColIndex, boolean handleOutOfMemoryError)
          Returns the value at chunkRowIndex, chunkColIndex, chunkCellRowIndex, chunkCellColIndex as a double.
 double getCellDouble(long cellRowIndex, long cellColIndex, boolean handleOutOfMemoryError)
          Returns the value at cellRowIndex, cellColIndex as a double
 double getCellDouble(java.awt.geom.Point2D.Double point, boolean handleOutOfMemoryError)
          Returns the value of the cell at point as a double.
 Grid2DSquareCellAbstract.CellID getCellID(double x, double y, boolean handleOutOfMemoryError)
          Returns a CellID of the cell given by x-coordinate x, y-coordinate y even if that cell would not be in the grid.
 Grid2DSquareCellAbstract.CellID getCellID(long cellRowIndex, long cellColIndex, boolean handleOutOfMemoryError)
          Returns a CellID of the cell given by cellRowIndex, cellColIndex even if that cell would not be in the grid.
 Grid2DSquareCellAbstract.CellID[] getCellIDs(double x, double y, double distance, boolean handleOutOfMemoryError)
          Returns a CellID[] - the cell IDs for cells thats centroids are intersected by circle with centre at x-coordinate x, y-coordinate y, and radius distance.
protected  Grid2DSquareCellAbstract.CellID[] getCellIDs(double x, double y, long cellRowIndex, long cellColIndex, double distance, boolean handleOutOfMemoryError)
          Returns double[] cells - the values for cells thats centroids would be intersected by circle with centre at x-coordinate x, y-coordinate y, and radius distance.
 Grid2DSquareCellAbstract.CellID[] getCellIDs(long cellRowIndex, long cellColIndex, double distance, boolean handleOutOfMemoryError)
          Returns a CellID[] - the cell IDs for cells thats centroids would be intersected by circle with centre at centroid of cell given by cell row index cellRowIndex, cell column index cellColIndex, and radius distance.
 int getCellInt(Grid2DSquareCellChunkAbstract grid2DSquareCellChunk, int chunkRowIndex, int chunkColIndex, int chunkCellRowIndex, int chunkCellColIndex, boolean handleOutOfMemoryError)
          Returns the value at chunkRowIndex, chunkColIndex, chunkCellRowIndex, chunkCellColIndex as a int.
 int getCellInt(int chunkRowIndex, int chunkColIndex, int chunkCellRowIndex, int chunkCellColIndex, boolean handleOutOfMemoryError)
          Returns the value at chunkRowIndex, chunkColIndex, chunkCellRowIndex, chunkCellColIndex as a int.
 int getCellInt(long cellRowIndex, long cellColIndex, boolean handleOutOfMemoryError)
          Returns the value at cellRowIndex, cellColIndex as a int.
 long getCellRowIndex(java.math.BigDecimal yBigDecimal, boolean handleOutOfMemoryError)
          Returns the cell row Index for the cells that intersect the y-coordinate yBigDecimal.
 long getCellRowIndex(double y, boolean handleOutOfMemoryError)
          Returns the cell row Index for the cells that intersect the y-coordinate y.
 double getCellsizeDouble(boolean handleOutOfMemoryError)
          Returns dimensions[0] converted to a double.
 double getCellX(Grid2DSquareCellAbstract.CellID cellID, boolean handleOutOfMemoryError)
          Deprecated. use getCellXDouble(CellID,boolean) Returns the x-coordinate of the centroid for cell with cell ID cellID as a double.
 double getCellX(long cellColIndex, boolean handleOutOfMemoryError)
          Deprecated. use getCellXDouble(long,boolean) Returns the x-coordinate of the centroid for cells with column index cellColIndex as a double.
 java.math.BigDecimal getCellXBigDecimal(Grid2DSquareCellAbstract.CellID cellID, boolean handleOutOfMemoryError)
          Returns the x-coordinate of the centroid for cell with cell ID cellID as a BigDecimal.
 java.math.BigDecimal getCellXBigDecimal(long cellColIndex, boolean handleOutOfMemoryError)
          Returns the x-coordinate of the centroid for cells with column index cellColIndex as a BigDecimal.
 double getCellXDouble(Grid2DSquareCellAbstract.CellID cellID, boolean handleOutOfMemoryError)
          Returns the x-coordinate of the centroid for cell with cell ID cellID as a double
 double getCellXDouble(long cellColIndex, boolean handleOutOfMemoryError)
          Returns the x-coordinate of the centroid for cells with column index cellColIndex as a double.
 double getCellY(Grid2DSquareCellAbstract.CellID cellID, boolean handleOutOfMemoryError)
          Deprecated. use getCellYDouble(CellID,boolean) Returns the y-coordinate of the centroid of cell with CellID cellID as a double.
 double getCellY(long cellRowIndex, boolean handleOutOfMemoryError)
          Deprecated. use getCellYDouble(long,boolean) Returns the y-coordinate of the centroid for cells with row index cellRowIndex as a double.
 java.math.BigDecimal getCellYBigDecimal(Grid2DSquareCellAbstract.CellID cellID, boolean handleOutOfMemoryError)
          Returns the y-coordinate of the centroid of cell with CellID cellID as a BigDecimal.
 java.math.BigDecimal getCellYBigDecimal(long cellRowIndex, boolean handleOutOfMemoryError)
          Returns the y-coordinate of the centroid for cells with row index cellRowIndex as a BigDecimal.
 double getCellYDouble(Grid2DSquareCellAbstract.CellID cellID, boolean handleOutOfMemoryError)
          Returns the y-coordinate of the centroid of cell with CellID cellID as a double.
 double getCellYDouble(long cellRowIndex, boolean handleOutOfMemoryError)
          Returns the y-coordinate of the centroid for cells with row index cellRowIndex as a double.
 int getChunkCellColIndex(double x, boolean handleOutOfMemoryError)
          Returns the chunk cell column Index of the cells that intersect the x-coordinate x.
 int getChunkCellColIndex(long cellColIndex, boolean handleOutOfMemoryError)
          Returns the chunks cell column index of the cell in the chunk thats centoid is closest to the x-coordinate x.
 int getChunkCellRowIndex(double y, boolean handleOutOfMemoryError)
          Returns the chunk cell row Index of the cells that intersects the y-coordinate y.
 int getChunkCellRowIndex(long cellRowIndex, boolean handleOutOfMemoryError)
          Returns the chunks cell row Index of the cells in the chunk thats centoid is closest to the y-coordinate y.
 int getChunkColIndex(double x, boolean handleOutOfMemoryError)
          Returns the chunk column index for the chunks intersecting the x-coordinate x.
 int getChunkColIndex(long cellColIndex, boolean handleOutOfMemoryError)
          Returns the chunk column index for the chunk intersecting the cell at cell column index cellColIndex.
 int getChunkNcols(boolean handleOutOfMemoryError)
          Returns chunkNcols.
 int getChunkNcols(Grid2DSquareCellAbstract.ChunkID chunkID, boolean handleOutOfMemoryError)
          Returns the number of columns in chunkID as an int
 int getChunkNcolsFinalColChunks(boolean handleOutOfMemoryError)
          Returns the number of cols in the final col Chunk
 int getChunkNrows(boolean handleOutOfMemoryError)
          Returns chunkNrows.
 int getChunkNrows(Grid2DSquareCellAbstract.ChunkID chunkID, boolean handleOutOfMemoryError)
          Returns the number of rows in chunkID as an int
 int getChunkNrowsFinalRowChunks(boolean handleOutOfMemoryError)
          Returns the number of rows in the final row Chunk
 int getChunkRowIndex(double y, boolean handleOutOfMemoryError)
          Returns the chunk row index for the chunks intersecting the y-coordinate y.
 int getChunkRowIndex(long cellRowIndex, boolean handleOutOfMemoryError)
          Returns the chunk row index for the chunk intersecting the cell at cell row index cellRowIndex.
 java.math.BigDecimal[] getDimensions()
          Returns dimensions.
 int getDimensionsScale(boolean handleOutOfMemoryError)
          Returns dimensionsScale.
 java.io.File getDirectory()
          Returns directory.
protected  Grid2DSquareCellChunkAbstract getGrid2DSquareCellChunk(Grid2DSquareCellAbstract.ChunkID chunkID, boolean handleOutOfMemoryError)
          Returns grid2DSquareCellChunks.
protected  Grid2DSquareCellChunkAbstract getGrid2DSquareCellChunk(int chunkRowIndex, int chunkColIndex, boolean handleOutOfMemoryError)
          Returns the Grid2DSquareCellChunkAbstract with the given chunkRowIndex and chunkColIndex
protected  java.util.HashMap getGrid2DSquareCellChunks()
          Returns this.grid2DSquareCellChunks TODO: Should we clone, i.e.
 double[] getGridBounds(boolean handleOutOfMemoryError)
          Returns gridBounds (the bounding box of the grid) as a double[] where; gridBounds[0] xmin, left most x-coordinate of this gridBounds[1] ymin, lowest y-coordinate of this gridBounds[2] xmax, right most x-coordinate of this gridBounds[3] ymax, highest y-coordinate of this
 GridStatisticsAbstract getGridStatistics()
          Returns this.gridStatistics TODO: For safety, this method should probably be removed and instead, this class be made to implement GridStatisticsInterface.
 java.math.BigDecimal getHeightBigDecimal(boolean handleOutOfMemoryError)
          Returns the height of the grid.
 double getHeightDouble(boolean handleOutOfMemoryError)
          Returns the height of the grid.
 java.lang.String getName()
          Returns name.
 int getNChunkCols(boolean handleOutOfMemoryError)
          Returns nChunkCols.
 int getNChunkRows(boolean handleOutOfMemoryError)
          Returns nChunkRows.
 long getNcols()
          Returns ncols.
 Grid2DSquareCellAbstract.CellID getNearestCellID(double x, double y, boolean handleOutOfMemoryError)
          Returns the the nearest cells cellRowIndex and cellColIndex as a long[] from ID to point given by x-coordinate x, y-coordinate y.
protected  Grid2DSquareCellAbstract.CellID getNearestCellID(double x, double y, long cellRowIndex, long cellColIndex, boolean handleOutOfMemoryError)
          Returns the the nearest CellID to point given by x-coordinate x, y-coordinate y in position given by cellRowIndex, cellColIndex.
 Grid2DSquareCellAbstract.CellID getNearestCellID(long cellRowIndex, long cellColIndex, boolean handleOutOfMemoryError)
          Returns the the nearest cells cellRowIndex and cellColIndex as a long[] from ID to point given by cell row index cellRowIndex, cell column index cellColIndex.
 Grid2DSquareCellAbstract.ChunkID getNextChunk(Grid2DSquareCellAbstract.ChunkID chunkID, int nChunkRows, int nChunkCols, boolean handleOutOfMemoryError)
          Returns the next ChunkID in row major order from chunkID, or null.
 Grid2DSquareCellAbstract.ChunkID getNextChunkRowMinor(Grid2DSquareCellAbstract.ChunkID chunkID, int nChunkRows, int nChunkCols, boolean handleOutOfMemoryError)
          Returns the next ChunkID in row minor order from this, or null.
abstract  java.math.BigDecimal getNoDataValueBigDecimal(boolean handleOutOfMemoryError)
          Returns the noDataValue of this as a BigDecimal.
 double getNoDataValueDouble(boolean handleOutOfMemoryError)
          Deprecated. This should not be used Returns the noDataValue of this as a double.
 long getNrows()
          Returns nrows.
 Grid2DSquareCellAbstract.ChunkID getPreviousChunk(Grid2DSquareCellAbstract.ChunkID chunkID, int nChunkRows, int nChunkCols, boolean handleOutOfMemoryError)
          Returns the next ChunkID in row major order from this, or null.
 java.math.BigDecimal getWidthBigDecimal(boolean handleOutOfMemoryError)
          Returns the width of the grid as a BigDecimal.
 double getWidthDouble(boolean handleOutOfMemoryError)
          Returns the width of the grid as a double.
protected  boolean inGrid(java.math.BigDecimal xBigDecimal, java.math.BigDecimal yBigDecimal, boolean handleOutOfMemoryError)
          Returns true iff point given by x-coordinate x, y-coordinate y is in the Grid.
 boolean inGrid(double x, double y, boolean handleOutOfMemoryError)
          Returns true iff point given by x-coordinate x, y-coordinate y is in the Grid.
 boolean inGrid(Grid2DSquareCellAbstract.CellID cellID, boolean handleOutOfMemoryError)
          Returns true iff cell given by cellID is in the Grid.
 boolean inGrid(Grid2DSquareCellAbstract.ChunkID chunkID, boolean handleOutOfMemoryError)
          Returns true iff ChunkID chunkID is in the Grid.
 boolean inGrid(int chunkRowIndex, int chunkColIndex, boolean handleOutOfMemoryError)
          Returns true iff position given by chunk row index chunkRowIndex, chunk column index chunkColIndex is in the Grid.
 boolean inGrid(int chunkRowIndex, int chunkColIndex, int chunkCellRowIndex, int chunkCellColIndex, boolean handleOutOfMemoryError)
          Returns true iff cell given by chunkRowIndex, chunkColIndex, chunkCellRowIndex, chunkCellColIndex is in the Grid.
 boolean inGrid(long cellRowIndex, long cellColIndex, boolean handleOutOfMemoryError)
          Returns true iff position given by cell row index cellRowIndex, cell column index cellColIndex is in the Grid.
protected abstract  void initAll(Grid2DSquareCellAbstract grid2DSquareCellAbstract)
          Initialises all fields from an existing instance.
protected  void initAll(Grid2DSquareCellAbstract grid2DSquareCell, boolean flag)
          Initialises all fields from an existing instance including grid2DSquareCellDoubleChunks.
protected  void initChunkNcols(int chunkNcols)
          Initialises chunkNcols.
protected  void initChunkNrows(int chunkNrows)
          Initialises chunkNrows.
protected  void initDimensions(java.math.BigDecimal[] dimensions)
          Initialises dimensions.
 void initNChunkCols(long ncols, int chunkNcols)
          Initialises nChunkCols
 void initNChunkRows(long nrows, int chunkNrows)
          Initialises nChunkRows
protected  void initNcols(long ncols)
          Initialises ncols.
protected  void initNrows(long nrows)
          Initialises nrows.
 boolean isCached(Grid2DSquareCellAbstract.ChunkID chunkID, boolean reinitialiseMemoryReserve)
          Returns true iff grid2DSquareCellChunk given by chunkID is cached.
abstract  java.util.Iterator iterator(boolean handleOutOfMemoryError)
          Returns an iterator over the cell values in this.
 void restoreChunk(Grid2DSquareCellAbstract.ChunkID chunkID, boolean handleOutOfMemoryError)
          Restores a grid2DSquareCellChunk from a cache.
 void restoreChunk(int chunkRowIndex, int chunkColIndex, boolean handleOutOfMemoryError)
          Restores a grid2DSquareCellChunk from a cache.
 void setChunk(Grid2DSquareCellChunkAbstract grid2DSquareCellChunk, Grid2DSquareCellAbstract.ChunkID chunkID, boolean handleOutOfMemoryError)
          Sets chunk with chunkID to grid2DSquareCellDoubleChunk.
 void setName(java.lang.String newName, boolean handleOutOfMemoryError)
          Sets name.
abstract  java.lang.String toString(boolean handleOutOfMemoryError)
          Returns a string description of the instance.
 java.lang.String toString(boolean handleOutOfMemoryError, boolean flag)
          Returns a string description of the Abstract fields of this instance.
 
Methods inherited from class uk.ac.leeds.ccg.andyt.grids.utilities.ErrorHandler
clearMemoryReserve, initMemoryReserve, initMemoryReserve
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

directory

protected java.io.File directory
Local directory used for caching.


grid2DSquareCellChunks

protected java.util.HashMap grid2DSquareCellChunks
The chunks that make up this instance. HashMap is prefered to an array or an array of arrays due to garbage collection caching advantages. TODO: 1. Would it be better to use a; ReferenceMap, ReferenceIdentityMap, IdentityHashMap, or Hashtable in place of this HashMap? 2. Should this be transient?


gridStatistics

protected GridStatisticsAbstract gridStatistics
A reference to the grid Statistics Object.


nChunkRows

protected int nChunkRows
For storing the number of chunk rows.


nChunkCols

protected int nChunkCols
For storing the number of chunk columns.


chunkNrows

protected int chunkNrows
For storing the (usual) number of cells in a chunk row. This may be different for chunks in the final row of chunks (final as in row major order)


chunkNcols

protected int chunkNcols
For storing the (usual) number of cells in a chunk column. This may be different for chunks in the final row of chunks (final as in row major order)


nrows

protected long nrows
For storing the number of rows in the grid.


ncols

protected long ncols
For storing the number of columns in the grid.


name

protected java.lang.String name
For storing the name of the grid.


dimensions

protected java.math.BigDecimal[] dimensions
For storing cellsize, minx, miny, maxx, maxy Although maxx and maxy could be easily calculated if required, for convenience they are calculated by default during grid construction.


dimensionsScale

protected int dimensionsScale
For storing the minimum number of decimal places needed to store the dimensions.


unsignedLongPowersOf2

protected static UnsignedLongPowersOf2 unsignedLongPowersOf2
For storing values mapped to a binary encoded long. The long is a key which indicates if the value is that at a given location. Both keys and values are unique. This is used in Grid2DSquareCellDoubleChunk64CellMap.

Constructor Detail

Grid2DSquareCellAbstract

public Grid2DSquareCellAbstract()
Method Detail

initAll

protected abstract void initAll(Grid2DSquareCellAbstract grid2DSquareCellAbstract)
Initialises all fields from an existing instance. Main use in constructors: Grid2DSquareCellDouble(File,File,ObjectInputStream). Grid2DSquareCellInt(File,File,ObjectInputStream).

Parameters:
grid2DSquareCellAbstract - the Grid2DSquareCellAbstract from which the field values of this are set.

initAll

protected void initAll(Grid2DSquareCellAbstract grid2DSquareCell,
                       boolean flag)
Initialises all fields from an existing instance including grid2DSquareCellDoubleChunks. For use with constructors: Grid2DSquareCellDouble(File,File,ObjectInputStream). Grid2DSquareCellInt(File,File,ObjectInputStream).

Parameters:
grid2DSquareCell - the Grid2DSquareCellAbstract from which the field values of this are set.
flag - This is to distinguish this method from initMain( Grid2DSquareCellAbstract )

getGrid2DSquareCellChunks

protected java.util.HashMap getGrid2DSquareCellChunks()
Returns this.grid2DSquareCellChunks TODO: Should we clone, i.e. and return this.grid2DSquareCellChunks.clone()? The methods for caching and clearing in core need not directly refer to this.grid2DSquareCellChunks. The method is protected to avoid problems of freeing memory by caching and clearing which can be caused if an external Object holds a reference to an Object in this.grid2DSquareCellChunks.


getGridStatistics

public GridStatisticsAbstract getGridStatistics()
Returns this.gridStatistics TODO: For safety, this method should probably be removed and instead, this class be made to implement GridStatisticsInterface. This done the methods introduced would be made to call the relevant ones in this.gridStatistics.


getGrid2DSquareCellChunk

protected Grid2DSquareCellChunkAbstract getGrid2DSquareCellChunk(int chunkRowIndex,
                                                                 int chunkColIndex,
                                                                 boolean handleOutOfMemoryError)
Returns the Grid2DSquareCellChunkAbstract with the given chunkRowIndex and chunkColIndex

Parameters:
chunkRowIndex -
chunkColIndex -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getGrid2DSquareCellChunk

protected Grid2DSquareCellChunkAbstract getGrid2DSquareCellChunk(Grid2DSquareCellAbstract.ChunkID chunkID,
                                                                 boolean handleOutOfMemoryError)
Returns grid2DSquareCellChunks.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

iterator

public abstract java.util.Iterator iterator(boolean handleOutOfMemoryError)
Returns an iterator over the cell values in this.


toString

public abstract java.lang.String toString(boolean handleOutOfMemoryError)
Returns a string description of the instance.


toString

public java.lang.String toString(boolean handleOutOfMemoryError,
                                 boolean flag)
Returns a string description of the Abstract fields of this instance.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.
flag - This is ignored. It is simply to distinguish this method from the abstract method toString(boolean).

getDirectory

public java.io.File getDirectory()
Returns directory.


setName

public void setName(java.lang.String newName,
                    boolean handleOutOfMemoryError)
Sets name.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getName

public java.lang.String getName()
Returns name.


setChunk

public void setChunk(Grid2DSquareCellChunkAbstract grid2DSquareCellChunk,
                     Grid2DSquareCellAbstract.ChunkID chunkID,
                     boolean handleOutOfMemoryError)
Sets chunk with chunkID to grid2DSquareCellDoubleChunk.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getNcols

public final long getNcols()
Returns ncols.


initNcols

protected final void initNcols(long ncols)
Initialises ncols.


getNrows

public final long getNrows()
Returns nrows.


initNrows

protected final void initNrows(long nrows)
Initialises nrows.


getNChunkRows

public final int getNChunkRows(boolean handleOutOfMemoryError)
Returns nChunkRows.


initNChunkRows

public final void initNChunkRows(long nrows,
                                 int chunkNrows)
Initialises nChunkRows

Parameters:
nrows -
chunkNrows -

getNChunkCols

public final int getNChunkCols(boolean handleOutOfMemoryError)
Returns nChunkCols.


initNChunkCols

public final void initNChunkCols(long ncols,
                                 int chunkNcols)
Initialises nChunkCols

Parameters:
ncols -
chunkNcols -

getChunkNrows

public final int getChunkNrows(boolean handleOutOfMemoryError)
Returns chunkNrows.


initChunkNrows

protected final void initChunkNrows(int chunkNrows)
Initialises chunkNrows.


getChunkNcols

public final int getChunkNcols(boolean handleOutOfMemoryError)
Returns chunkNcols.


initChunkNcols

protected final void initChunkNcols(int chunkNcols)
Initialises chunkNcols.


getChunkNrowsFinalRowChunks

public final int getChunkNrowsFinalRowChunks(boolean handleOutOfMemoryError)
Returns the number of rows in the final row Chunk

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getChunkNcolsFinalColChunks

public final int getChunkNcolsFinalColChunks(boolean handleOutOfMemoryError)
Returns the number of cols in the final col Chunk

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getChunkNrows

public final int getChunkNrows(Grid2DSquareCellAbstract.ChunkID chunkID,
                               boolean handleOutOfMemoryError)
Returns the number of rows in chunkID as an int

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getChunkNcols

public final int getChunkNcols(Grid2DSquareCellAbstract.ChunkID chunkID,
                               boolean handleOutOfMemoryError)
Returns the number of columns in chunkID as an int

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getDimensions

public final java.math.BigDecimal[] getDimensions()
Returns dimensions.


getCellsizeDouble

public final double getCellsizeDouble(boolean handleOutOfMemoryError)
Returns dimensions[0] converted to a double.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getDimensionsScale

public final int getDimensionsScale(boolean handleOutOfMemoryError)
Returns dimensionsScale.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

initDimensions

protected final void initDimensions(java.math.BigDecimal[] dimensions)
Initialises dimensions.


getCellDouble

public double getCellDouble(java.awt.geom.Point2D.Double point,
                            boolean handleOutOfMemoryError)
Returns the value of the cell at point as a double.

Parameters:
point - The Point2D.Double for which the cell value is returned.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellDouble

public double getCellDouble(long cellRowIndex,
                            long cellColIndex,
                            boolean handleOutOfMemoryError)
Returns the value at cellRowIndex, cellColIndex as a double

Parameters:
cellRowIndex - The cell row index.
cellColIndex - The cell column index.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellDouble

public double getCellDouble(int chunkRowIndex,
                            int chunkColIndex,
                            int chunkCellRowIndex,
                            int chunkCellColIndex,
                            boolean handleOutOfMemoryError)
Returns the value at chunkRowIndex, chunkColIndex, chunkCellRowIndex, chunkCellColIndex as a double.

Parameters:
chunkRowIndex - The cell chunk row index.
chunkColIndex - The cell chunk column index.
chunkCellRowIndex - The cell row index of the chunk.
chunkCellColIndex - The cell column index of the chunk.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellDouble

public double getCellDouble(Grid2DSquareCellChunkAbstract grid2DSquareCellChunk,
                            int chunkRowIndex,
                            int chunkColIndex,
                            int chunkCellRowIndex,
                            int chunkCellColIndex,
                            boolean handleOutOfMemoryError)
Returns the value at chunkRowIndex, chunkColIndex, chunkCellRowIndex, chunkCellColIndex as a double.

Parameters:
grid2DSquareCellChunk - The Grid2DSquareCellChunkAbstract containing the cell.
chunkRowIndex - The cell chunk row index.
chunkColIndex - The cell chunk column index.
chunkCellRowIndex - The cell row index of the chunk.
chunkCellColIndex - The cell column index of the chunk.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellInt

public int getCellInt(long cellRowIndex,
                      long cellColIndex,
                      boolean handleOutOfMemoryError)
Returns the value at cellRowIndex, cellColIndex as a int.

Parameters:
cellRowIndex - The cell row index.
cellColIndex - The cell column index.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellInt

public int getCellInt(int chunkRowIndex,
                      int chunkColIndex,
                      int chunkCellRowIndex,
                      int chunkCellColIndex,
                      boolean handleOutOfMemoryError)
Returns the value at chunkRowIndex, chunkColIndex, chunkCellRowIndex, chunkCellColIndex as a int.

Parameters:
chunkRowIndex - The cell chunk row index.
chunkColIndex - The cell chunk column index.
chunkCellRowIndex - The cell row index of the chunk.
chunkCellColIndex - The cell column index of the chunk.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellInt

public int getCellInt(Grid2DSquareCellChunkAbstract grid2DSquareCellChunk,
                      int chunkRowIndex,
                      int chunkColIndex,
                      int chunkCellRowIndex,
                      int chunkCellColIndex,
                      boolean handleOutOfMemoryError)
Returns the value at chunkRowIndex, chunkColIndex, chunkCellRowIndex, chunkCellColIndex as a int.

Parameters:
grid2DSquareCellChunk - The Grid2DSquareCellChunkAbstract containing the cell.
chunkRowIndex - The cell chunk row index.
chunkColIndex - The cell chunk column index.
chunkCellRowIndex - The cell row index of the chunk.
chunkCellColIndex - The cell column index of the chunk.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getChunkColIndex

public final int getChunkColIndex(double x,
                                  boolean handleOutOfMemoryError)
Returns the chunk column index for the chunks intersecting the x-coordinate x.

Parameters:
x -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getChunkColIndex

public final int getChunkColIndex(long cellColIndex,
                                  boolean handleOutOfMemoryError)
Returns the chunk column index for the chunk intersecting the cell at cell column index cellColIndex.

Parameters:
cellColIndex -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellColIndex

public final long getCellColIndex(double x,
                                  boolean handleOutOfMemoryError)
Returns the cell column Index for the cells that intersect the x-coordinate x.

Parameters:
x -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellColIndex

public final long getCellColIndex(java.math.BigDecimal xBigDecimal,
                                  boolean handleOutOfMemoryError)
Returns the cell column Index for the cells that intersect the x-coordinate x.

Parameters:
xBigDecimal -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getChunkCellColIndex

public final int getChunkCellColIndex(double x,
                                      boolean handleOutOfMemoryError)
Returns the chunk cell column Index of the cells that intersect the x-coordinate x.

Parameters:
x -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getChunkCellColIndex

public final int getChunkCellColIndex(long cellColIndex,
                                      boolean handleOutOfMemoryError)
Returns the chunks cell column index of the cell in the chunk thats centoid is closest to the x-coordinate x.

Parameters:
cellColIndex -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getChunkRowIndex

public final int getChunkRowIndex(double y,
                                  boolean handleOutOfMemoryError)
Returns the chunk row index for the chunks intersecting the y-coordinate y.

Parameters:
y -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getChunkRowIndex

public final int getChunkRowIndex(long cellRowIndex,
                                  boolean handleOutOfMemoryError)
Returns the chunk row index for the chunk intersecting the cell at cell row index cellRowIndex.

Parameters:
cellRowIndex -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellRowIndex

public final long getCellRowIndex(double y,
                                  boolean handleOutOfMemoryError)
Returns the cell row Index for the cells that intersect the y-coordinate y.

Parameters:
y -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellRowIndex

public final long getCellRowIndex(java.math.BigDecimal yBigDecimal,
                                  boolean handleOutOfMemoryError)
Returns the cell row Index for the cells that intersect the y-coordinate yBigDecimal.

Parameters:
yBigDecimal - The y-coordinate for which the cell row index is returned.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getChunkCellRowIndex

public final int getChunkCellRowIndex(double y,
                                      boolean handleOutOfMemoryError)
Returns the chunk cell row Index of the cells that intersects the y-coordinate y.

Parameters:
y - .
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getChunkCellRowIndex

public final int getChunkCellRowIndex(long cellRowIndex,
                                      boolean handleOutOfMemoryError)
Returns the chunks cell row Index of the cells in the chunk thats centoid is closest to the y-coordinate y.

Parameters:
cellRowIndex - .
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellID

public final Grid2DSquareCellAbstract.CellID getCellID(long cellRowIndex,
                                                       long cellColIndex,
                                                       boolean handleOutOfMemoryError)
Returns a CellID of the cell given by cellRowIndex, cellColIndex even if that cell would not be in the grid.

Parameters:
cellRowIndex - The cell row index.
cellColIndex - The cell column index.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellID

public final Grid2DSquareCellAbstract.CellID getCellID(double x,
                                                       double y,
                                                       boolean handleOutOfMemoryError)
Returns a CellID of the cell given by x-coordinate x, y-coordinate y even if that cell would not be in the grid.

Parameters:
x - The x-coordinate.
y - The y-coordinate.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

cache

public final void cache(boolean cacheChunks,
                        boolean reinitialiseMemoryReserve)
A method to cache this instance by writing it out to an ObjectOutputStream File called Cache to be located in the File (directory) returned by getDirectory(). If cacheChunks is true then each of this.grid2DSquareCellChunks is cached first.

Parameters:
cacheChunks - If true then chunks are cached individually prior to caching this.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

cacheChunk

public final Grid2DSquareCellAbstract.ChunkID cacheChunk(boolean reinitialiseMemoryReserve)
Attempts to cache a seriailized version of a Chunk. Returns the ChunkID of that which was cached. The first chunk that is attempted to be cached is that with a chunk row index of 0, and a chunk column index of 0.

Parameters:
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

cacheChunk

public final boolean cacheChunk(int chunkRowIndex,
                                int chunkColIndex,
                                boolean reinitialiseMemoryReserve)
Attempts to cache a seriailized version of Chunk given by; chunk row index chunkRowIndex, chunk column index chunkColIndex. Returns true if chunk was cached and false otherwise. (NB. Sufficient memory should be available. Encountering an OutOfMemoryError is likely to be fatal.)

Parameters:
chunkRowIndex - The chunk row index.
chunkColIndex - The chunk column index.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

cacheChunk

public final boolean cacheChunk(Grid2DSquareCellAbstract.ChunkID chunkID,
                                boolean reinitialiseMemoryReserve)
Caches a seriailsed version of Chunk with given chunkID. (NB. Sufficient memory should be available. Encountering an OutOfMemoryError is likely to be fatal.)

Parameters:
chunkID - The chunkID of the chunk to be cached to file.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

cacheChunks

public final void cacheChunks(boolean reinitialiseMemoryReserve)
Caches a seriailsed version of all grid2DSquareCellChunks.

Parameters:
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

cacheChunks

public final void cacheChunks(java.util.HashSet chunkIDs,
                              boolean reinitialiseMemoryReserve)
Caches a seriailsed version of all grid2DSquareCellChunks in grid2DSquareCellChunkIDs.

Parameters:
chunkIDs - A HashSet containing the ChunkIDs of the grid2DSquareCellChunks to be cached.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

cacheChunksExcept

public final void cacheChunksExcept(Grid2DSquareCellAbstract.ChunkID chunkID,
                                    boolean reinitialiseMemoryReserve)
Caches all grid2DSquareCellChunks other that with ChunkID chunkID.

Parameters:
chunkID - The ChunkID of the chunk not to be cached.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

cacheChunkExcept

public final Grid2DSquareCellAbstract.ChunkID cacheChunkExcept(Grid2DSquareCellAbstract.ChunkID chunkID,
                                                               boolean reinitialiseMemoryReserve)
Caches a Grid2DSquareCellChunk of grid2DSquareCellChunks (other that with ChunkID chunkID) then returns its ChunkID. The first chunk that is attempted to be cached is that with a chunk row index of 0, and a chunk column index of 0.

Parameters:
chunkID - The ChunkID of the chunk not to be cached.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

cacheChunkExcept

public final Grid2DSquareCellAbstract.ChunkID cacheChunkExcept(int chunkRowIndex,
                                                               int chunkColIndex,
                                                               boolean reinitialiseMemoryReserve)
Caches a Grid2DSquareCellChunk of grid2DSquareCellChunks (other that with; chunk row index chunkRowIndex, chunk column index chunkColIndex) then returns its ChunkID. The first chunk that is attempted to be cached is that with a chunk row index of 0, and a chunk column index of 0.

Parameters:
chunkRowIndex - The chunk row index.
chunkColIndex - The chunk column index.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

cacheChunkExceptReverseOrder

public final Grid2DSquareCellAbstract.ChunkID cacheChunkExceptReverseOrder(int chunkRowIndex,
                                                                           int chunkColIndex,
                                                                           boolean reinitialiseMemoryReserve)
Caches a Grid2DSquareCellChunk of grid2DSquareCellChunks (other that with ChunkID chunkID) then returns its ChunkID. The first chunk that is attempted to be cached is that with a chunk row index of chunkNrows - 1, and a chunk column index of chunkNcols - 1. This is primarily used in constructors that read a data format that presents values in reverse row order.

Parameters:
chunkRowIndex - The chunk row index.
chunkColIndex - The chunk column index.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

cacheChunkExceptReverseOrder

public final Grid2DSquareCellAbstract.ChunkID cacheChunkExceptReverseOrder(Grid2DSquareCellAbstract.ChunkID chunkID,
                                                                           boolean reinitialiseMemoryReserve)
Caches a Grid2DSquareCellChunk of grid2DSquareCellChunks (other that with ChunkID chunkID) then returns its ChunkID. The first chunk that is attempted to be cached is that with a chunk row index of chunkNrows - 1, and a chunk column index of chunkNcols - 1. This is primarily used in constructors that read a data format that presents values in reverse row order.

Parameters:
chunkID - The ChunkID of the chunk not to be cached.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

cacheChunksExcept

public final void cacheChunksExcept(java.util.HashSet chunkIDs,
                                    boolean reinitialiseMemoryReserve)
Caches all grid2DSquareCellChunks other than those with ChunkIDs in chunkIDs.

Parameters:
chunkIDs - A hashSet containing ChunkIDs not to be cached.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

cacheAndClearChunks

public final void cacheAndClearChunks(boolean reinitialiseMemoryReserve)
Caches a seriailsed version of all grid2DSquareCellChunks and clears them.

Parameters:
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

isCached

public final boolean isCached(Grid2DSquareCellAbstract.ChunkID chunkID,
                              boolean reinitialiseMemoryReserve)
Returns true iff grid2DSquareCellChunk given by chunkID is cached. This must be an upToDate cache.

Parameters:
chunkID - The ChunkID of the grid2DSquareCellChunk tested to see if it is cached.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

clearChunk

public final void clearChunk(int chunkRowIndex,
                             int chunkColIndex,
                             boolean reinitialiseMemoryReserve)
For releasing a grid2DSquareCellChunk stored in memory. This is usually only done after the equivallent of cacheChunk(chunkRowIndex,chunkColIndex) has been called.

Parameters:
chunkRowIndex - The chunk row index of the grid2DSquareCellChunk to be cleared.
chunkColIndex - The chunk column index of the grid2DSquareCellChunk to be cleared.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

clearChunk

public final void clearChunk(Grid2DSquareCellAbstract.ChunkID chunkID)
For releasing a grid2DSquareCellChunk stored in memory. This is usually only done after the equivallent of cacheChunk(chunkID) has been called.

Parameters:
chunkID - The ChunkID of the grid2DSquareCellChunk to be cleared.

clearChunks

public final void clearChunks(boolean reinitialiseMemoryReserve)
For releasing all grid2DSquareCellChunk stored in memory. This is usually only done after the cacheChunks() has been called.

Parameters:
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

clearChunks

public final void clearChunks(java.util.HashSet chunkIDs,
                              boolean reinitialiseMemoryReserve)
Clears Grid2DSquareCellChunkAbstracts with ChunkIDs in chunkIDs.

Parameters:
chunkIDs - A HashSet containing the ChunkIDs of the Grid2DSquareCellChunkAbstracts to be cleared.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

clearChunkExcept

public final void clearChunkExcept(Grid2DSquareCellAbstract.ChunkID chunkID,
                                   boolean reinitialiseMemoryReserve)
For releasing a grid2DSquareCellChunk stored in memory except that with ChunkID given by chunkID.

Parameters:
chunkID - The ChunkID of the grid2DSquareCellChunk not to be cleared.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

clearChunksExcept

public final void clearChunksExcept(Grid2DSquareCellAbstract.ChunkID chunkID,
                                    boolean reinitialiseMemoryReserve)
For releasing all grid2DSquareCellChunk stored in memory except that with ChunkID given by chunkID.

Parameters:
chunkID - The ChunkID of the grid2DSquareCellChunk not to be cleared.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

clearChunksExcept

public final void clearChunksExcept(java.util.HashSet chunkIDs,
                                    boolean reinitialiseMemoryReserve)
For releasing all grid2DSquareCellChunk stored in memory except those with ChunkIDs in chunkIDs.

Parameters:
chunkIDs - The HashSet of ChunkIDs of the grid2DSquareCellChunks not to be cleared.
reinitialiseMemoryReserve - If true then this.memoryReserve is initialised prior to returning from this method.

restoreChunk

public final void restoreChunk(int chunkRowIndex,
                               int chunkColIndex,
                               boolean handleOutOfMemoryError)
Restores a grid2DSquareCellChunk from a cache.

Parameters:
chunkRowIndex - The chunk row index of the grid2DSquareCellChunk to be restored.
chunkColIndex - The chunk column index of the grid2DSquareCellChunk to be restored.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

restoreChunk

public final void restoreChunk(Grid2DSquareCellAbstract.ChunkID chunkID,
                               boolean handleOutOfMemoryError)
Restores a grid2DSquareCellChunk from a cache.

Parameters:
chunkID - The ChunkID of the grid2DSquareCellChunk to be restored.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellIDs

public final Grid2DSquareCellAbstract.CellID[] getCellIDs(double x,
                                                          double y,
                                                          double distance,
                                                          boolean handleOutOfMemoryError)
Returns a CellID[] - the cell IDs for cells thats centroids are intersected by circle with centre at x-coordinate x, y-coordinate y, and radius distance.

Parameters:
x - the x-coordinate of the circle centre from which cell values are returned.
y - the y-coordinate of the circle centre from which cell values are returned.
distance - the radius of the circle for which intersected cell values are returned.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellIDs

public final Grid2DSquareCellAbstract.CellID[] getCellIDs(long cellRowIndex,
                                                          long cellColIndex,
                                                          double distance,
                                                          boolean handleOutOfMemoryError)
Returns a CellID[] - the cell IDs for cells thats centroids would be intersected by circle with centre at centroid of cell given by cell row index cellRowIndex, cell column index cellColIndex, and radius distance.

Parameters:
cellRowIndex - the row index for the cell thats centroid is the circle centre from which cell values are returned.
cellColIndex - the column index for the cell thats centroid is the circle centre from which cell values are returned.
distance - the radius of the circle for which intersected cell values are returned.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellIDs

protected Grid2DSquareCellAbstract.CellID[] getCellIDs(double x,
                                                       double y,
                                                       long cellRowIndex,
                                                       long cellColIndex,
                                                       double distance,
                                                       boolean handleOutOfMemoryError)
Returns double[] cells - the values for cells thats centroids would be intersected by circle with centre at x-coordinate x, y-coordinate y, and radius distance.

Parameters:
x - the x-coordinate of the circle centre from which cell values are returned.
y - the y-coordinate of the circle centre from which cell values are returned.
cellRowIndex - the row index at y.
cellColIndex - the col index at x.
distance - the radius of the circle for which intersected cell values are returned.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown. TODO: remove need for copy to new array.

getNearestCellID

public Grid2DSquareCellAbstract.CellID getNearestCellID(double x,
                                                        double y,
                                                        boolean handleOutOfMemoryError)
Returns the the nearest cells cellRowIndex and cellColIndex as a long[] from ID to point given by x-coordinate x, y-coordinate y.

Parameters:
x - the x-coordinate of the point.
y - the y-coordinate of the point.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getNearestCellID

public Grid2DSquareCellAbstract.CellID getNearestCellID(long cellRowIndex,
                                                        long cellColIndex,
                                                        boolean handleOutOfMemoryError)
Returns the the nearest cells cellRowIndex and cellColIndex as a long[] from ID to point given by cell row index cellRowIndex, cell column index cellColIndex.

Parameters:
cellRowIndex - the row index from which nearest cell ID is returned.
cellColIndex - the column index from which nearest cell ID is returned.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown. TODO: return CellID[] as could be more than one nearest CellID

getNearestCellID

protected Grid2DSquareCellAbstract.CellID getNearestCellID(double x,
                                                           double y,
                                                           long cellRowIndex,
                                                           long cellColIndex,
                                                           boolean handleOutOfMemoryError)
Returns the the nearest CellID to point given by x-coordinate x, y-coordinate y in position given by cellRowIndex, cellColIndex.

Parameters:
x - The x-coordinate of the point.
y - The y-coordinate of the point.
cellRowIndex - The cell row index of cell containing point.
cellColIndex - The cell column index of cell containing point.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getHeightDouble

public final double getHeightDouble(boolean handleOutOfMemoryError)
Returns the height of the grid.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getHeightBigDecimal

public final java.math.BigDecimal getHeightBigDecimal(boolean handleOutOfMemoryError)
Returns the height of the grid.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getWidthDouble

public final double getWidthDouble(boolean handleOutOfMemoryError)
Returns the width of the grid as a double.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getWidthBigDecimal

public final java.math.BigDecimal getWidthBigDecimal(boolean handleOutOfMemoryError)
Returns the width of the grid as a BigDecimal.

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

inGrid

protected final boolean inGrid(java.math.BigDecimal xBigDecimal,
                               java.math.BigDecimal yBigDecimal,
                               boolean handleOutOfMemoryError)
Returns true iff point given by x-coordinate x, y-coordinate y is in the Grid. Anything on the boundary is considered to be in.

Parameters:
xBigDecimal - The x-coordinate of the point.
yBigDecimal - The y-coordinate of the point.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

inGrid

public final boolean inGrid(double x,
                            double y,
                            boolean handleOutOfMemoryError)
Returns true iff point given by x-coordinate x, y-coordinate y is in the Grid. Anything on the boundary is considered to be in.

Parameters:
x - The x-coordinate of the point.
y - The y-coordinate of the point.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

inGrid

public final boolean inGrid(long cellRowIndex,
                            long cellColIndex,
                            boolean handleOutOfMemoryError)
Returns true iff position given by cell row index cellRowIndex, cell column index cellColIndex is in the Grid.

Parameters:
cellRowIndex - The cell row index to test.
cellColIndex - The cell column index to test.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

inGrid

public final boolean inGrid(int chunkRowIndex,
                            int chunkColIndex,
                            boolean handleOutOfMemoryError)
Returns true iff position given by chunk row index chunkRowIndex, chunk column index chunkColIndex is in the Grid.

Parameters:
chunkRowIndex - The chunk row index to test.
chunkColIndex - The chunk column index to test.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

inGrid

public final boolean inGrid(Grid2DSquareCellAbstract.CellID cellID,
                            boolean handleOutOfMemoryError)
Returns true iff cell given by cellID is in the Grid.

Parameters:
cellID - The CellID of a cell to test.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

inGrid

public final boolean inGrid(Grid2DSquareCellAbstract.ChunkID chunkID,
                            boolean handleOutOfMemoryError)
Returns true iff ChunkID chunkID is in the Grid.

Parameters:
chunkID - The ChunkID of a cell to test.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

inGrid

public final boolean inGrid(int chunkRowIndex,
                            int chunkColIndex,
                            int chunkCellRowIndex,
                            int chunkCellColIndex,
                            boolean handleOutOfMemoryError)
Returns true iff cell given by chunkRowIndex, chunkColIndex, chunkCellRowIndex, chunkCellColIndex is in the Grid.

Parameters:
chunkRowIndex -
chunkColIndex -
chunkCellRowIndex -
chunkCellColIndex -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellXBigDecimal

public final java.math.BigDecimal getCellXBigDecimal(long cellColIndex,
                                                     boolean handleOutOfMemoryError)
Returns the x-coordinate of the centroid for cells with column index cellColIndex as a BigDecimal.

Parameters:
cellColIndex - The cell column index thats centroid x-coordinate is returned.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellXDouble

public final double getCellXDouble(long cellColIndex,
                                   boolean handleOutOfMemoryError)
Returns the x-coordinate of the centroid for cells with column index cellColIndex as a double.

Parameters:
cellColIndex - The cell column index thats centroid x-coordinate is returned.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellX

@Deprecated
public final double getCellX(long cellColIndex,
                                        boolean handleOutOfMemoryError)
Deprecated. use getCellXDouble(long,boolean) Returns the x-coordinate of the centroid for cells with column index cellColIndex as a double.

Parameters:
cellColIndex - The cell column index thats centroid x-coordinate is returned.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellXBigDecimal

public final java.math.BigDecimal getCellXBigDecimal(Grid2DSquareCellAbstract.CellID cellID,
                                                     boolean handleOutOfMemoryError)
Returns the x-coordinate of the centroid for cell with cell ID cellID as a BigDecimal.

Parameters:
cellID -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellXDouble

public final double getCellXDouble(Grid2DSquareCellAbstract.CellID cellID,
                                   boolean handleOutOfMemoryError)
Returns the x-coordinate of the centroid for cell with cell ID cellID as a double

Parameters:
cellID -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellX

@Deprecated
public final double getCellX(Grid2DSquareCellAbstract.CellID cellID,
                                        boolean handleOutOfMemoryError)
Deprecated. use getCellXDouble(CellID,boolean) Returns the x-coordinate of the centroid for cell with cell ID cellID as a double.

Parameters:
cellID -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellYBigDecimal

public final java.math.BigDecimal getCellYBigDecimal(long cellRowIndex,
                                                     boolean handleOutOfMemoryError)
Returns the y-coordinate of the centroid for cells with row index cellRowIndex as a BigDecimal.

Parameters:
cellRowIndex - the cell column index thats centroid y-coordinate is returned.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellYDouble

public final double getCellYDouble(long cellRowIndex,
                                   boolean handleOutOfMemoryError)
Returns the y-coordinate of the centroid for cells with row index cellRowIndex as a double.

Parameters:
cellRowIndex - the cell column index thats centroid y-coordinate is returned.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellY

@Deprecated
public final double getCellY(long cellRowIndex,
                                        boolean handleOutOfMemoryError)
Deprecated. use getCellYDouble(long,boolean) Returns the y-coordinate of the centroid for cells with row index cellRowIndex as a double.

Parameters:
cellRowIndex - the cell column index thats centroid y-coordinate is returned.
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellYBigDecimal

public final java.math.BigDecimal getCellYBigDecimal(Grid2DSquareCellAbstract.CellID cellID,
                                                     boolean handleOutOfMemoryError)
Returns the y-coordinate of the centroid of cell with CellID cellID as a BigDecimal.

Parameters:
cellID -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellYDouble

public final double getCellYDouble(Grid2DSquareCellAbstract.CellID cellID,
                                   boolean handleOutOfMemoryError)
Returns the y-coordinate of the centroid of cell with CellID cellID as a double.

Parameters:
cellID -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellY

@Deprecated
public final double getCellY(Grid2DSquareCellAbstract.CellID cellID,
                                        boolean handleOutOfMemoryError)
Deprecated. use getCellYDouble(CellID,boolean) Returns the y-coordinate of the centroid of cell with CellID cellID as a double.

Parameters:
cellID -
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getGridBounds

public final double[] getGridBounds(boolean handleOutOfMemoryError)
Returns gridBounds (the bounding box of the grid) as a double[] where; gridBounds[0] xmin, left most x-coordinate of this gridBounds[1] ymin, lowest y-coordinate of this gridBounds[2] xmax, right most x-coordinate of this gridBounds[3] ymax, highest y-coordinate of this

Parameters:
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown. TODO: Are bounds in double range? Is there more than cellsize difference with precision? Throw appropriate exceptions.

getCellBoundsDoubleArray

public final double[] getCellBoundsDoubleArray(long cellRowIndex,
                                               long cellColIndex,
                                               boolean handleOutOfMemoryError)
Returns double[] where; double[0] xmin, left most x-coordinate of cell at (rowIndex,colIndex) double[1] ymin, lowest y-coordinate of cell at (rowIndex,colIndex) double[2] xmax, right most x-coordinate of cell at (rowIndex,colIndex) double[3] ymax, highest y-coordinate of cell at (rowIndex,colIndex)

Parameters:
cellRowIndex - the row index of the cell for which the bounds are returned
cellColIndex - the column index of the cell for which the bounds are returned
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown.

getCellBoundsDoubleArray

public final double[] getCellBoundsDoubleArray(double x,
                                               double y,
                                               boolean handleOutOfMemoryError)
Returns double[] where; double[0] xmin, left most x-coordinate of cell that intersects point at (x,y) double[1] ymin, lowest y-coordinate of cell that intersects point at (x,y) double[2] xmax, right most x-coordinate of cell that intersects point at (x,y) double[3] ymax, highest y-coordinate of cell that intersects point at (x,y)

Parameters:
x - the x-coordinate in the cell for which the bounds are returned
y - the y-coordinate in the cell for which the bounds are returned
handleOutOfMemoryError - If true then OutOfMemoryErrors are caught in this method then caching operations are initiated prior to retrying. If false then OutOfMemoryErrors are caught and thrown. TODO: Precision may compromise result. More precision is available via BigDecimal arithmetic.

getNoDataValueBigDecimal

public abstract java.math.BigDecimal getNoDataValueBigDecimal(boolean handleOutOfMemoryError)
Returns the noDataValue of this as a BigDecimal.


getNoDataValueDouble

@Deprecated
public double getNoDataValueDouble(boolean handleOutOfMemoryError)
Deprecated. This should not be used Returns the noDataValue of this as a double.

Parameters:
handleOutOfMemoryError - Controls whether OutOfMemoryError is handled via caching by this method. If true then caching initiated in this method, if false then OutOfMemoryError is thrown to be handled higher up by caller method. TODO: Test Handling for ArithmeticExceptions caused by rounding.

getNextChunk

public Grid2DSquareCellAbstract.ChunkID getNextChunk(Grid2DSquareCellAbstract.ChunkID chunkID,
                                                     int nChunkRows,
                                                     int nChunkCols,
                                                     boolean handleOutOfMemoryError)
Returns the next ChunkID in row major order from chunkID, or null.

Parameters:
chunkID -
nChunkRows -
nChunkCols -
handleOutOfMemoryError - TODO: Is it inefficient to pass in nChunkRows and nChunkCols since this has them already?

getNextChunkRowMinor

public Grid2DSquareCellAbstract.ChunkID getNextChunkRowMinor(Grid2DSquareCellAbstract.ChunkID chunkID,
                                                             int nChunkRows,
                                                             int nChunkCols,
                                                             boolean handleOutOfMemoryError)
Returns the next ChunkID in row minor order from this, or null.

Parameters:
chunkID -
nChunkRows -
nChunkCols -
handleOutOfMemoryError - TODO: Is it inefficient to pass in nChunkRows and nChunkCols since this has them already?

getPreviousChunk

public Grid2DSquareCellAbstract.ChunkID getPreviousChunk(Grid2DSquareCellAbstract.ChunkID chunkID,
                                                         int nChunkRows,
                                                         int nChunkCols,
                                                         boolean handleOutOfMemoryError)
Returns the next ChunkID in row major order from this, or null.

Parameters:
chunkID -
nChunkRows -
nChunkCols -
handleOutOfMemoryError - TODO: Is it inefficient to pass in nChunkRows and nChunkCols since this has them already?