|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.opensha.commons.data.ContainerSubset2D<T>
public class ContainerSubset2D<T>
Title: ContainerSubset2D
Description: Small read only window into larger Container2d. This class takes a Container2D as a variable, then becomes a "window" into the larger grid. Since this class implements Container2DAPI it "looks" like a Container2D.
All this class does is provide convinience methods to zoom into a smaller section of the referenced Container2D. It translates the window x and y coordinate indices into the real indices of the referenced container.
The key to understanding this class is the Window2D that contains a minX, maxX, minY and maxY values. These are the translation indices to go between this subset coordinate system to the referencing container's coordinate system. For example the 0th index along x axis in this subset container maps to minX index in the main container.
Another trick used in this class is useful to understand. Basically the API allows translation, modifications of the Window2D around the larger referenced container. Because there are four variables to the Window2D, this could take four method calls to change the data. Because there is more than one step involved, and any one step can potentially fail, I needed to provide a rollback mechanism to the last know good state. This is the purpose of the oldWindow variable and the commit and rollback functions.
This class was designed with the purpose of examining rupture locals in a fault gridded surface, but has been generalized to work with any Container2DAPI.
| Field Summary | |
|---|---|
protected static String |
C
Class name used for debbuging |
protected static boolean |
D
if true print out debugging statements |
protected Container2D<T> |
data
Internal reference to real data container. |
protected String |
name
Every container has a name associated with it to distinguish it from other container instances. |
protected Window2D |
oldWindow
The API allows translation, modifications of the Window2D around the larger referenced container. |
protected static char |
TAB
|
protected Window2D |
window
Data containing indexing information into larger dataset. |
| Constructor Summary | |
|---|---|
ContainerSubset2D(int numRows,
int numCols,
int startRow,
int startCol)
Constructor for the ContainerSubset2D object. |
|
ContainerSubset2D(int numRows,
int numCols,
int startRow,
int startCol,
Container2D<T> data)
Constructor for the ContainerSubset2D object. |
|
| Method Summary | |
|---|---|
void |
clear()
Sublcass not allowed to modify data, i.e. |
protected void |
commit()
Completes a transaction. |
boolean |
exist(int row,
int column)
Returns true if a non-null java object resides at the specified cell, i.e. |
T |
get(int row,
int column)
Returns the object stored in the Container2D at the subset's window coordinates. |
ListIterator<T> |
getAllByColumnsIterator()
Iterate over all cells in the subset window. |
ListIterator<T> |
getAllByRowsIterator()
Iterate over all cells in the subset window. |
ListIterator<T> |
getColumnIterator(int row)
Iterate over all columns values in one row of the surface. |
Container2D<T> |
getContainer2D()
Returns the container2D pointer contained in the subset window. |
int |
getEndCol()
Returns the last col index on the Window2D |
int |
getEndRow()
Returns the last row index on the Window2D |
String |
getName()
Returns the name of this object |
int |
getNumCols()
Returns number of cols in the Window2D. |
int |
getNumRows()
Returns number of rows in the Window2D. |
ListIterator<T> |
getRowIterator(int column)
Iterate over all row values in one column of the surface. |
int |
getStartCol()
Gets the startColindex of the Window2D object |
int |
getStartRow()
Gets the startRow index of the Window2D object |
protected void |
initTransaction()
Start of a transaction - simply clones the Window2D into the old Window. |
Iterator<T> |
iterator()
|
ListIterator<T> |
listIterator()
iterate over all data points, no guarentee of order returned |
static void |
main(String[] args)
The main program for the Container2D class. |
protected void |
rollback()
Copies the oldWindow back into the Window2D, restoring the window to it's previous size. |
void |
set(int row,
int column,
T obj)
This method is required of the Contianer2dAPI. |
void |
setContainer2D(Container2D<T> data)
Allows setting the reference to a new Container2D. |
void |
setName(String name)
Every container has a name associated with it to distinguish it from other container instances. |
void |
setStartCol(int startCol)
Used to update the starting cal index in the Window2D. |
void |
setStartRow(int startRow)
Used to update the starting row index in the Window2D. |
void |
shiftCols(int delta)
Shifts the Window2D "window" into the main Container2D by the specified number of index points. |
void |
shiftRows(int delta)
Shifts the Window2D "window" into the main Container2D by the specified number of index points. |
long |
size()
Returns the size of the subset window, numRows * numCols. |
Object[][] |
toJava2D()
Use Window2D to generate this. |
String |
toString()
Prints out each location and fault information for debugging |
protected void |
validate()
Internal helper function that performs various validation checks between the Window2D values and the referenced container domain and range values. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
protected static final String C
protected static final boolean D
protected String name
protected Window2D window
protected Window2D oldWindow
protected Container2D<T> data
protected static final char TAB
| Constructor Detail |
|---|
public ContainerSubset2D(int numRows,
int numCols,
int startRow,
int startCol)
throws ArrayIndexOutOfBoundsException
numRows - number of index points along the x-axisnumCols - number of index points along the y-axisstartRow - Staring row of this subset, put in Window2DstartCol - Staring col of this subset, put in Window2D
ArrayIndexOutOfBoundsException - Thown if any of the idices go beyond the range of the referencing container
public ContainerSubset2D(int numRows,
int numCols,
int startRow,
int startCol,
Container2D<T> data)
throws ArrayIndexOutOfBoundsException
numRows - number of index points along the x-axisnumCols - number of index points along the y-axisstartRow - Staring row of this subset, put in Window2DstartCol - Staring col of this subset, put in Window2D
ArrayIndexOutOfBoundsException - Thown if any of the idices go beyond the range of the referencing container| Method Detail |
|---|
public void setContainer2D(Container2D<T> data)
throws ArrayIndexOutOfBoundsException
data - The new container2D value
ArrayIndexOutOfBoundsException - Thown if any of the idices go beyond the range of the referencing container
public void setStartRow(int startRow)
throws ArrayIndexOutOfBoundsException
startRow - The new startRow value
ArrayIndexOutOfBoundsException - Thrown if this start row is an invalid index in the main container, i.e. too large or negative.
protected void validate()
throws ArrayIndexOutOfBoundsException
ArrayIndexOutOfBoundsException - Thrown if any of the values are invalid, such as negative indices.
public void setStartCol(int startCol)
throws ArrayIndexOutOfBoundsException
startRow - The new startCal value in Window2D
ArrayIndexOutOfBoundsException - Thrown if this start cal is an invalid index in the main container, i.e. too large or negative.
public void set(int row,
int column,
T obj)
throws ArrayIndexOutOfBoundsException
set in interface Container2D<T>row - x-coordcolumn - y-coordobj - new object to place in the container cell
ArrayIndexOutOfBoundsException - Never thrown, function disabled.public Container2D<T> getContainer2D()
public int getStartRow()
public int getStartCol()
public int getNumRows()
getNumRows in interface Container2D<T>public int getNumCols()
getNumCols in interface Container2D<T>public int getEndRow()
public int getEndCol()
public T get(int row,
int column)
throws ArrayIndexOutOfBoundsException
get in interface Container2D<T>row - x-coordcolumn - y-coord
ArrayIndexOutOfBoundsException - If the indices value are invalid for the container2D
public ListIterator<T> getColumnIterator(int row)
throws ArrayIndexOutOfBoundsException
getColumnIterator in interface Container2D<T>row - Row to get all column points from
ArrayIndexOutOfBoundsException - If the x-coord index value are invalid for the container2D
public ListIterator<T> getRowIterator(int column)
throws ArrayIndexOutOfBoundsException
getRowIterator in interface Container2D<T>row - Column to get all row points from
ArrayIndexOutOfBoundsException - If the y-coord index value are invalid for the container2Dpublic ListIterator<T> getAllByColumnsIterator()
Note: This iterates only over the subset indices, not over the full container. The iterator implementation is contained as an inner class in this clas file.
getAllByColumnsIterator in interface Container2D<T>public ListIterator<T> getAllByRowsIterator()
Note: This iterates only over the subset indices, not over the full container. The iterator implementation is contained as an inner class in this clas file.
getAllByRowsIterator in interface Container2D<T>
public void shiftRows(int delta)
throws ArrayIndexOutOfBoundsException
delta - Number of points to shift the Window2D along the x-axis
ArrayIndexOutOfBoundsException - Thrown if the shift moves the window outside the main container boundaries.protected void initTransaction()
protected void rollback()
protected void commit()
public void shiftCols(int delta)
throws ArrayIndexOutOfBoundsException
delta - Number of points to shift the Window2D along the y-axis
ArrayIndexOutOfBoundsException - Thrown if the shift moves the window outside the main container boundaries.public long size()
size in interface Container2D<T>
public boolean exist(int row,
int column)
exist in interface Container2D<T>row - x-coordcolumn - y-coord
public void clear()
clear in interface Container2D<T>public ListIterator<T> listIterator()
listIterator in interface Container2D<T>public Object[][] toJava2D()
public String toString()
toString in interface Container2D<T>toString in class Objectpublic static void main(String[] args)
args - The command line argumentspublic void setName(String name)
Container2D
setName in interface Container2D<T>public String getName()
Named
getName in interface Namedpublic Iterator<T> iterator()
iterator in interface Iterable<T>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||