org.opensha.commons.data
Class Window2D

java.lang.Object
  extended by org.opensha.commons.data.Window2D
All Implemented Interfaces:
Serializable

public class Window2D
extends Object
implements Serializable

Title: Window2D

Description: This class represents the sub indices of a window into a two dimensional matrix. A two dimensional matrix is usually specified by x and y coordinates, i.e. rows and columns. So a two dimensional matrix will have a max number of rows and a max number of columns. This window will have a start row and start column, end row and end column which determines the number of rows and columns that you are peering into.

This class is the data model ( javabean ) used by ContainerSubset2D to provide the indices as a window into the main Container2D matrix referenced within the ContainerSubset2D.

Version:
1.0
Author:
Steven W. Rock
See Also:
Serialized Form

Field Summary
protected static String C
          Class name used for debugging.
protected static boolean D
          If true debugging statements are printed.
protected  int endCol
          The last column of the window.
protected  int endRow
          The last row of the window.
protected  int maxNumCols
          The full number of columns in the full matrix.
protected  int maxNumRows
          The number of rows in the full matrix.
protected  int numCols
          The number of columns in this window.
protected  int numRows
          The number of rows in this window.
protected  int startCol
          The first column of the window.
protected  int startRow
          The first row of the window.
 
Constructor Summary
Window2D()
          No-arg Constructor - does nothing.
 
Method Summary
 void calcUpperBounds()
          This function calculates the end row and column based on the user input of start row column and num rows and columns.
 void checkLowerBounds(String S)
          Checks that the specified row and column are valid indices into the 2D array.
 void checkUpperBounds(String S)
          Checks that the specified row and column are valid indices into the 2D array.
 Object clone()
          Returns an exact copy of this window.
 Window2D cloneWindow()
          Returns an exact copy of this window.
 boolean equals(Object obj)
          This function returns true if the input window has the same variables values as this window.
 boolean equalsWindow(Window2D window)
          This function returns true if the input window has the same variables values as this window.
 int getEndCol()
          Gets the endCol - javabean method
 int getEndRow()
          Gets the endRow - javabean method
 int getMaxNumCols()
          Gets the maxNumCols - javabean method
 int getMaxNumRows()
          Gets the maxNumRows - javabean method
 int getNumCols()
          Gets the numCols - javabean method
 int getNumRows()
          Gets the numRows - javabean method
 int getStartCol()
          Gets the startCol - javabean method
 int getStartRow()
          Returns the first row of the window.
 int getTranslatedCol(int col)
          Takes an input col of the window subset and translates it back to the original larger matrix.In other words adds the start col to the input col.
 int getTranslatedRow(int row)
          Takes an input row of the window subset and translates it back to the original larger matrix.
 boolean isValidCol(int col)
          This function determines if the specified input col fits within the window.
 boolean isValidRow(int row)
          This function determines if the specified row fits within the window.
 void setEndCol(int endCol)
          Sets the endCol - javabean method
 void setEndRow(int endRow)
          Sets the endRow - javabean method
 void setNumCols(int numCols)
          Sets the numCols - javabean method
 void setNumRows(int numRows)
          Sets the numRows - javabean method
 void setStartCol(int startCol)
          Sets the startCol - javabean method
 void setStartRow(int startRow)
          Sets the startRow - javabean method
 void shiftCols(int delta)
          Shift the start col of your window by delta.
 void shiftRows(int delta)
          Shift the start row of your window by delta.
 String toString()
          Helper function used for debugging.
 int windowSize()
          Returns the number of rows times the num of columns in this window.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

C

protected static final String C
Class name used for debugging.

See Also:
Constant Field Values

D

protected static final boolean D
If true debugging statements are printed.

See Also:
Constant Field Values

startRow

protected int startRow
The first row of the window.


endRow

protected int endRow
The last row of the window.


numRows

protected int numRows
The number of rows in this window.


maxNumRows

protected int maxNumRows
The number of rows in the full matrix.


startCol

protected int startCol
The first column of the window.


endCol

protected int endCol
The last column of the window.


numCols

protected int numCols
The number of columns in this window.


maxNumCols

protected int maxNumCols
The full number of columns in the full matrix.

Constructor Detail

Window2D

public Window2D()
No-arg Constructor - does nothing.

Method Detail

isValidRow

public boolean isValidRow(int row)
This function determines if the specified row fits within the window. It does not go past the end row.

Parameters:
row - The row you wish to return from the window subset
Returns:
True if the row is within range, false otherwise.

getStartRow

public int getStartRow()
Returns the first row of the window.


isValidCol

public boolean isValidCol(int col)
This function determines if the specified input col fits within the window. It can not go past the end col.

Parameters:
col - The col you wish to return of the window subset
Returns:
True if the col is within range. False otherwise.

getTranslatedRow

public int getTranslatedRow(int row)
Takes an input row of the window subset and translates it back to the original larger matrix. In other words adds the start row to the input row. So if you specify 0 the result would return 20 if 20 was the start row in the original matrix.

Parameters:
row - Input row you wish to translate to the original matrix row.
Returns:
The translated Row value

getTranslatedCol

public int getTranslatedCol(int col)
Takes an input col of the window subset and translates it back to the original larger matrix.In other words adds the start col to the input col. So if you specify 0 the result would return 20 if 20 was the start col in the original matrix.

Parameters:
col - Input col you wish to translate to the original matrix col.
Returns:
The translated Col value

windowSize

public int windowSize()
Returns the number of rows times the num of columns in this window.

Returns:
numRows * numCol

shiftRows

public void shiftRows(int delta)
               throws ArrayIndexOutOfBoundsException
Shift the start row of your window by delta. If delta is negative it will shift the window to a smaller starting row. If positive it will shift it to a larger starting row.

Parameters:
delta - The amount you wish to shift the window in index units.
Throws:
ArrayIndexOutOfBoundsException - This exception is thrown if the shift moves the windows either into negative values or outside the range of the original matrix.

shiftCols

public void shiftCols(int delta)
               throws ArrayIndexOutOfBoundsException
Shift the start col of your window by delta. If delta is negative it will shift the window to a smaller col. If positive it will shift it to a larger col.

Parameters:
delta - The amount you wish to shift the window in index units.
Throws:
ArrayIndexOutOfBoundsException - This exception is thrown if the shift moves the windows either into negative values or outside the range of the original matrix.

calcUpperBounds

public void calcUpperBounds()
This function calculates the end row and column based on the user input of start row column and num rows and columns.


checkLowerBounds

public void checkLowerBounds(String S)
                      throws ArrayIndexOutOfBoundsException
Checks that the specified row and column are valid indices into the 2D array. This is a helper function that validates the user inputs that are all num larger than 0.

Parameters:
S - Debugging string used for error messaging.
Throws:
ArrayIndexOutOfBoundsException - Thrown if any of the window index information is less than zero.

checkUpperBounds

public void checkUpperBounds(String S)
                      throws ArrayIndexOutOfBoundsException
Checks that the specified row and column are valid indices into the 2D array. This is a heper function that validates that all start row and start col end row and end col are not larger than the original matrix max number of rows and max number of columns. In other words the window cannot go beyond the bounds of the original matrix.

Parameters:
S - Debugging string used for error messaging.
Throws:
ArrayIndexOutOfBoundsException - Thrown if any index of the window ie. start and end row and col fall beyond the maximum number of rows and columns in the original matrix.

clone

public Object clone()
Returns an exact copy of this window. You can change the clone without affecting this original data, this original instance.

Overrides:
clone in class Object
Returns:
A cloned copy of this window.

cloneWindow

public Window2D cloneWindow()
Returns an exact copy of this window. You can change the clone without affecting this original data, this original instance.

Returns:
A cloned copy of this window.

equalsWindow

public boolean equalsWindow(Window2D window)
This function returns true if the input window has the same variables values as this window.

Parameters:
window - The input window to compare to this object.
Returns:
True if all indices ie. class variables are the same.

equals

public boolean equals(Object obj)
This function returns true if the input window has the same variables values as this window.

Overrides:
equals in class Object
Parameters:
obj - The input window to compare to this object.
Returns:
True if all indices ie. class variables are the same.

toString

public String toString()
Helper function used for debugging. This function prints out all variables current values.

Overrides:
toString in class Object
Returns:
Formatted string of instance information.

setStartRow

public void setStartRow(int startRow)
Sets the startRow - javabean method


setStartCol

public void setStartCol(int startCol)
Sets the startCol - javabean method


getStartCol

public int getStartCol()
Gets the startCol - javabean method


getNumRows

public int getNumRows()
Gets the numRows - javabean method


getNumCols

public int getNumCols()
Gets the numCols - javabean method


getMaxNumRows

public int getMaxNumRows()
Gets the maxNumRows - javabean method


getMaxNumCols

public int getMaxNumCols()
Gets the maxNumCols - javabean method


getEndRow

public int getEndRow()
Gets the endRow - javabean method


getEndCol

public int getEndCol()
Gets the endCol - javabean method


setNumRows

public void setNumRows(int numRows)
Sets the numRows - javabean method


setNumCols

public void setNumCols(int numCols)
Sets the numCols - javabean method


setEndRow

public void setEndRow(int endRow)
Sets the endRow - javabean method


setEndCol

public void setEndCol(int endCol)
Sets the endCol - javabean method