com.mockrunner.jdbc
Class StringValuesTable

java.lang.Object
  extended by com.mockrunner.jdbc.StringValuesTable

public class StringValuesTable
extends java.lang.Object

A data structure providing tabular (row and column) access semantics to items within. While applicable to several usages, the primary purpose is (in conjunction with ArrayResultSetFactory) to provide for easy set up of unit test fixtures and assertion of outcomes with the same data structures, without any need for external sources of test data.

Author:
Erick G. Reid

Constructor Summary
StringValuesTable(java.lang.String name, java.lang.String[][] stringMatrix)
          Creates a new StringValuesTable with the given name, columns and string matrix.
StringValuesTable(java.lang.String name, java.lang.String[] columnNames, java.lang.String[][] stringMatrix)
          Creates a new StringValuesTable with the given name, columns and string matrix.
 
Method Summary
 java.lang.String[] getColumn(int columnNumber)
          Returns the contents of the given column.
 java.lang.String[] getColumn(java.lang.String columnName)
          Returns the contents of the given column.
 java.lang.String[] getColumnNames()
          Returns the column names.
 java.lang.String getItem(int rowNumber, int columnNumber)
          Returns the item found in the string matrix at the given coordinate.
 java.lang.String getItem(int rowNumber, java.lang.String columnName)
          Returns the item found in the string matrix at the given coordinate.
 java.lang.String getName()
          Returns the table name.
 int getNumberOfColumns()
          Returns the number of columns found in the string matrix for this StringValuesTable.
 int getNumberOfRows()
          Returns the number of rows found in the string matrix for this StringValuesTable.
 java.lang.String[] getRow(int rowNumber)
          Returns the elements of the given row.
 java.lang.String[][] getStringMatrix()
          Returns the tabular data for this StringValuesTable.
 boolean isValidColumnName(java.lang.String columnName)
          Returns true if the given column name is valid for this StringValuesTable; returns false otherwise.
 boolean isValidColumnNumber(int columnNumber)
          Returns true if the given column number is valid for this StringValuesTable; returns false otherwise.
 boolean isValidRowNumber(int row)
          Returns true if the given row number is valid for this StringValuesTable; returns false otherwise.
static java.lang.String[] verifyColumnNames(java.lang.String[] columnNames, java.lang.String[][] stringMatrix)
          Returns the given array if it is found to indeed be valid according to the published contract.
static java.lang.String[][] verifyStringMatrix(java.lang.String[][] stringMatrix)
          Returns the given matrix if it is found to indeed be valid according to the published contract.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringValuesTable

public StringValuesTable(java.lang.String name,
                         java.lang.String[][] stringMatrix)
Creates a new StringValuesTable with the given name, columns and string matrix.

Parameters:
name - the table name. This argument cannot be null and must contain at least 1 non-blank character.
stringMatrix - the string matrix. This argument cannot be null, must not contain any null values, and each array in the matrix must contain the same number of elements as the first (stringMatrix[0].length == stringMatrix[n].length for any given valid row number, n). Further, this matrix must, at a minimum represent 1 row and 1 column of items (stringMatrix.length >= 1, and stringMatrix[0].length >= 1).

StringValuesTable

public StringValuesTable(java.lang.String name,
                         java.lang.String[] columnNames,
                         java.lang.String[][] stringMatrix)
Creates a new StringValuesTable with the given name, columns and string matrix.

Parameters:
name - the table name. This argument cannot be null and must contain at least 1 non-blank character.
columnNames - the names for the columns in this StringValuesTable. This argument may be null if no column names are desired, but if a non-null array reference is given, the array cannot contain any null nor duplicate elements, and must have the same number of elements as there are columns in the given string matrix (stringMatrix[n] for any given valid row number, n).
stringMatrix - the string matrix. This argument cannot be null, must not contain any null values, and each array in the matrix must contain the same number of elements as the first (stringMatrix[0].length == stringMatrix[n].length for any given valid row number, n). Further, this matrix must, at a minimum represent 1 row and 1 column of items (stringMatrix.length >= 1, and stringMatrix[0].length >= 1).
Method Detail

getColumn

public java.lang.String[] getColumn(java.lang.String columnName)
Returns the contents of the given column.

Parameters:
columnName - the name of the desired column. This argument cannot be null and must be a valid column for this StringValuesTable.
Returns:
the contents of the given column.

getColumn

public java.lang.String[] getColumn(int columnNumber)
Returns the contents of the given column.

Parameters:
columnNumber - the index of the desired column (1-based). This argument must be a valid column index for this StringValuesTable.
Returns:
the contents of the given column.

getColumnNames

public java.lang.String[] getColumnNames()
Returns the column names. This array may be empty if column names are not being used.

Returns:
the column names.

getItem

public java.lang.String getItem(int rowNumber,
                                java.lang.String columnName)
Returns the item found in the string matrix at the given coordinate.

Parameters:
rowNumber - the number of the desired row (1-based). This argument must be a valid row number for this StringValuesTable.
columnName - the name of the desired column. This argument cannot be null and must be a valid column for this StringValuesTable.
Returns:
the item found in the string matrix at the given coordinate.

getItem

public java.lang.String getItem(int rowNumber,
                                int columnNumber)
Returns the item found in the string matrix at the given coordinate.

Parameters:
rowNumber - the number of the desired row (1-based). This argument must be a valid row number for this StringValuesTable.
columnNumber - the index of the desired column (1-based). This argument must be a valid column index for this StringValuesTable.
Returns:
the item found in the string matrix at the given coordinate.

getName

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

Returns:
the table name.

getNumberOfColumns

public int getNumberOfColumns()
Returns the number of columns found in the string matrix for this StringValuesTable.

Returns:
the number of columns found in the string matrix for this StringValuesTable.

getNumberOfRows

public int getNumberOfRows()
Returns the number of rows found in the string matrix for this StringValuesTable.

Returns:
the number of rows found in the string matrix for this StringValuesTable.

getRow

public java.lang.String[] getRow(int rowNumber)
Returns the elements of the given row.

Parameters:
rowNumber - the number of the desired row (1-based). This argument must be a valid row number for this StringValuesTable.
Returns:
the elements of the given row.

isValidColumnName

public boolean isValidColumnName(java.lang.String columnName)
Returns true if the given column name is valid for this StringValuesTable; returns false otherwise.

Parameters:
columnName - the column name to verify.
Returns:
true if the given column name is valid for this StringValuesTable.

isValidColumnNumber

public boolean isValidColumnNumber(int columnNumber)
Returns true if the given column number is valid for this StringValuesTable; returns false otherwise.

Parameters:
columnNumber - the column number to verify.
Returns:
true if the given column number is valid for this StringValuesTable.

isValidRowNumber

public boolean isValidRowNumber(int row)
Returns true if the given row number is valid for this StringValuesTable; returns false otherwise.

Parameters:
row - the row number to verify.
Returns:
true if the given index is valid for this StringValuesTable.

getStringMatrix

public java.lang.String[][] getStringMatrix()
Returns the tabular data for this StringValuesTable.

Returns:
the tabular data for this StringValuesTable.

verifyColumnNames

public static java.lang.String[] verifyColumnNames(java.lang.String[] columnNames,
                                                   java.lang.String[][] stringMatrix)
Returns the given array if it is found to indeed be valid according to the published contract.


verifyStringMatrix

public static java.lang.String[][] verifyStringMatrix(java.lang.String[][] stringMatrix)
Returns the given matrix if it is found to indeed be valid according to the published contract.