com.datamessenger.util
Class RecordSet


java.lang.Object

  |

  +--com.datamessenger.util.RecordSet

Direct Known Subclasses:
Table

public class RecordSet
extends java.lang.Object
implements java.lang.Cloneable

Provides a table for storing tabular data. The data is mapped to column and row coordinates. Table columns can be named for any unique Object value.

Copyright: Copyright (c) 2000 Jon L. Boynton

Company: Produx House, Corp

Version:
1.0
Author:
Jon L. Boynton

Field Summary
protected  java.util.Vector header
           
protected  int length
           
protected  int width
           
 
Constructor Summary
RecordSet()
          Creates an empty RecordSet.
RecordSet(int width)
          Creates a RecodSet with the specified number of columns.
RecordSet(java.lang.Object[] fields)
          Creates a RecodSet with a number of columns equal to the length of an Object array.
RecordSet(java.util.Vector fields)
          Creates a RecodSet with a number of columns equal to the size of a Vector.
 
Method Summary
 void add(RecordSet records)
           
 void addColumn(java.lang.Object name)
          Adds a column to the right edge of the RecordsSet.
 java.lang.Object clone()
          Creates a shallow copy of this RecordSet.
 void deleteColumnAt(int col)
          Removes the column at the specified index.
 void deleteRowAt(int row)
          Remove a row at the specified index.
 void fill(java.lang.Object[][] data, int col, int row, int width)
          Fills a range in the RecordSet with values from an Object[][].
 void fill(java.lang.Object name, java.lang.Object value, FillConstraints c)
          Adds a value to the next cell indicated by a constrains object.
 Record getColumn(int index)
          Gets a copy of a column record by it's index value.
 Record getColumn(java.lang.Object name)
          Gets a copy of the column record for the specified name.
protected  Record getColumnForName(java.lang.Object name)
          Gets the actual Record Object for the specified name.
 int getColumnIndex(java.lang.Object name)
          Finds the index for a column with the specified field name.
 int getColumnIndex(java.lang.Object name, int fromIndex)
          Finds the index for a column with the specified field name begining at the specified index.
 FillConstraints getFillConstraints()
          Creates a default constaints Object for filling the rows of this RecordSet with new data.
 java.util.Vector getHeader()
          Creates an ordered Vector containing the keys mapped to each Column.
 java.lang.Object getNameField()
          Identifies a prefered field for naming a record.
 java.lang.Object[][] getRecord(int row)
          Creates an 2D array containing the column name objects and the elements of a single row this RecordSet.
 java.lang.Object[][] getRecords()
          Creates an 2D array containing all elements of this RecordSet.
 java.lang.Object[][] getRecords(int startx, int starty, int endx, int endy)
          Creates an 2D array containg the elements from a range of Records.
 RecordSet getRecordSetInstance()
          Creates a new empty RecordSet with the same column fields.
 Record getRow(int index)
          Creates a row record from an index value.
 java.lang.Object getValue(int col, int row)
          Finds the cell value in a column at a row index.
 java.lang.Object getValue(java.lang.Object col, int row)
          Finds the cell value in a column at a row index.
 java.util.Vector getValues()
           
 int indexOf(java.lang.Object value, java.lang.Object columnName)
          Finds the row index of a value in a column with the specified name.
 int indexOf(java.lang.Object value, java.lang.Object columnName, int fromIndex)
          Finds the row index of a value in a column with the specified name and starting index.
 void insertColumnAt(java.lang.Object name, int col)
          Inserts a new column at the specified index.
 void insertRowAt(int row)
          Inserts a row at the specified index.
 int length()
          The number of rows in the RecordSet.
 java.lang.Object lock()
           
 Record lookUp(java.lang.Object value, java.lang.Object name)
          Finds a row record by looking up a value in the specified column.
 Record lookUp(java.lang.Object value, java.lang.Object name, int index)
          Finds a row record by looking up a value in the specified column from the specified index.
 RecordSet lookUpAll(java.lang.Object value, java.lang.Object name)
          Finds all records with matching values in the specified column.
 void print()
           
 void setLength(int length)
          Sets the length of the RecordSet.
 void setNameField(java.lang.Object name)
          Identifies a prefered field for naming a record.
 void setValue(java.lang.Object value, int col, int row)
          Sets the cell value in a column at a row index.
 void setValue(java.lang.Object value, java.lang.Object col, int row)
          Sets the cell value in a column at a row index.
 void setWidth(int width)
          Sets the width of the RecordSet.
 int width()
          The number of columns in the RecordSet.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

header


protected java.util.Vector header

length


protected int length

width


protected int width
Constructor Detail

RecordSet


public RecordSet()
Creates an empty RecordSet.

RecordSet


public RecordSet(int width)
Creates a RecodSet with the specified number of columns.
Parameters:
width - the number of columns. This constructor defines the column names by using the A-Z format common to spreadsheets.

RecordSet


public RecordSet(java.util.Vector fields)
Creates a RecodSet with a number of columns equal to the size of a Vector. Vector elements are used as keys for defining column names.
Parameters:
fields - the header field names.
See Also:
#getValue(Object, Object)

RecordSet


public RecordSet(java.lang.Object[] fields)
Creates a RecodSet with a number of columns equal to the length of an Object array. Array elements are used as keys for defining column names.
Parameters:
fields - the header field names.
Method Detail

getColumnIndex


public int getColumnIndex(java.lang.Object name)
Finds the index for a column with the specified field name.
Parameters:
name - the column name.
Returns:
the column index or -1 if not found.

getColumnIndex


public int getColumnIndex(java.lang.Object name,

                          int fromIndex)
Finds the index for a column with the specified field name begining at the specified index.
Parameters:
name - the column name.
Returns:
the column index or -1 if not found.

getColumn


public Record getColumn(java.lang.Object name)
Gets a copy of the column record for the specified name.
Parameters:
name - the column name.
Returns:
a cloned column Record or null (if name is invalid).

getColumnForName


protected Record getColumnForName(java.lang.Object name)
Gets the actual Record Object for the specified name. The Record returned by this method should not be modified, for any reason, by subclasses of RecordSet. This method is only intended for use as an efficent means of searching a specific column.
Parameters:
name - the column name.
Returns:
a column Record or null (if name is invalid).

getColumn


public Record getColumn(int index)
Gets a copy of a column record by it's index value.
Parameters:
the - column index starting at 0.

addColumn


public void addColumn(java.lang.Object name)
Adds a column to the right edge of the RecordsSet.
Parameters:
name - The column name Object

insertColumnAt


public void insertColumnAt(java.lang.Object name,

                           int col)
Inserts a new column at the specified index. Columns at or above the index are shifted to the right.
Parameters:
name - The column name Object
col - the insert index.
Throws:
ArrayIndexOutOfBoundsException() -  

deleteColumnAt


public void deleteColumnAt(int col)
Removes the column at the specified index. Columns above the index are shifted to the left.
Parameters:
col - the column index.
Throws:
ArrayIndexOutOfBoundsException() -  

getRow


public Record getRow(int index)
Creates a row record from an index value. The Records name is equal to the Integer value of the row index.
Parameters:
the - row index starting at 0.
Throws:
ArrayIndexOutOfBoundsException() - if the RecordSet is not empty and the index is out of range.

insertRowAt


public void insertRowAt(int row)
Inserts a row at the specified index. Rows at or below the index (greater than the index row), are shifted down.
Parameters:
col - the insert index.
Throws:
ArrayIndexOutOfBoundsException() -  

deleteRowAt


public void deleteRowAt(int row)
Remove a row at the specified index. Rows below the index (greater than the index row), are shifted up.
Parameters:
col - the insert index.
Throws:
ArrayIndexOutOfBoundsException() -  

lookUp


public Record lookUp(java.lang.Object value,

                     java.lang.Object name)
Finds a row record by looking up a value in the specified column.
Parameters:
name - The name of the column being searched.
value - the value being searched for.
Returns:
the first row containing a matching value.
Throws:
NoSuchElementException(String) -  

lookUp


public Record lookUp(java.lang.Object value,

                     java.lang.Object name,

                     int index)
Finds a row record by looking up a value in the specified column from the specified index.
Parameters:
name - The name of the column being searched.
value - the value being searched for.
index - the begining row index for the search (inclusive).
Returns:
the first row containing a matching value.
Throws:
NoSuchElementException(String) -  

lookUpAll


public RecordSet lookUpAll(java.lang.Object value,

                           java.lang.Object name)
Finds all records with matching values in the specified column.
Parameters:
name - The name of the column being searched.
value - the value being searched for.
Returns:
a new RecordSet. The RecordSet is empty if no matches are found.

getFillConstraints


public FillConstraints getFillConstraints()
Creates a default constaints Object for filling the rows of this RecordSet with new data. The contraints are initialized to column 0, row 0. The contraints width is equal to the current number of columns. Sub-classes may override this method to provide context sensitive settings.
Returns:
a FillConstrains Object
See Also:
FillConstraints

fill


public void fill(java.lang.Object name,

                 java.lang.Object value,

                 FillConstraints c)
Adds a value to the next cell indicated by a constrains object. This method will increment the constaints to the next position.
Parameters:
name - The next column name.
value - the new cell value
c - a FillConstraints model.

fill


public void fill(java.lang.Object[][] data,

                 int col,

                 int row,

                 int width)
Fills a range in the RecordSet with values from an Object[][].
Parameters:
data - a Object[][] containg new data.
col - the left starting column index.
row - the top starting row index.
width - the number of columns to fill.
Throws:
ArrayIndexOutOfBoundsException() - if the width is geater than the width of the Object[][].

add


public void add(RecordSet records)

setLength


public void setLength(int length)
Sets the length of the RecordSet. New rows will contain null values.
Parameters:
length - the new length
Throws:
NegativeArraySizeException() - if length < 0.

setWidth


public void setWidth(int width)
Sets the width of the RecordSet. The names for added columns (if any) are equal to the index value for the A-Z format common to spreadsheets. Columns to the right of the specified width (if any) are deleted.
Parameters:
width - the new width
Throws:
NegativeArraySizeException() - if width < 0.

indexOf


public int indexOf(java.lang.Object value,

                   java.lang.Object columnName)
Finds the row index of a value in a column with the specified name.
Parameters:
value - the value being searched for.
columnName - The name of the column being searched.
Returns:
a row index or -1.

indexOf


public int indexOf(java.lang.Object value,

                   java.lang.Object columnName,

                   int fromIndex)
Finds the row index of a value in a column with the specified name and starting index.
Parameters:
value - the value being searched for.
columnName - The name of the column being searched.
fromIndex - the begining index for the search.
Returns:
a row index or -1.

getRecords


public java.lang.Object[][] getRecords()
Creates an 2D array containing all elements of this RecordSet. The array length is is equal to the length of the RecordSet and does not include a header.
Returns:
a 2D Object array of data

getRecords


public java.lang.Object[][] getRecords(int startx,

                                       int starty,

                                       int endx,

                                       int endy)
Creates an 2D array containg the elements from a range of Records. The array returned does not include header values.
Parameters:
startx - the starting column index (inclusive).
starty - the starting row index (inclusive).
endx - the ending column index (exclusive).
endy - the ending row index (exclusive).
Returns:
a 2D Object array of data
Throws:
ArrayIndexOutOfBoundsException() -  

getRecord


public java.lang.Object[][] getRecord(int row)
Creates an 2D array containing the column name objects and the elements of a single row this RecordSet. such that:

obj[0][0] = a name object
obj[0][1] = a value object

Returns:
a name/value record array.

getHeader


public java.util.Vector getHeader()
Creates an ordered Vector containing the keys mapped to each Column.
Returns:
the Column names.

getRecordSetInstance


public RecordSet getRecordSetInstance()
Creates a new empty RecordSet with the same column fields. Sub-classes should override this method to return an Object of the appropriate type.
Returns:
a new Recordset instance.

getValue


public java.lang.Object getValue(java.lang.Object col,

                                 int row)
Finds the cell value in a column at a row index.
Parameters:
col - the column name.
row - the row index.
Returns:
a cell value from the RecordSet or null if out of range.

getValue


public java.lang.Object getValue(int col,

                                 int row)
Finds the cell value in a column at a row index.
Parameters:
col - the column index.
row - the row index.
Returns:
a cell value from the RecordSet or null if out of range.

getValues


public java.util.Vector getValues()

setValue


public void setValue(java.lang.Object value,

                     java.lang.Object col,

                     int row)
Sets the cell value in a column at a row index.
Parameters:
col - the column name.
row - the row index.
Throws:
ArrayIndexOutOfBoundsException() - if the index is out of range.

setValue


public void setValue(java.lang.Object value,

                     int col,

                     int row)
Sets the cell value in a column at a row index.
Parameters:
col - the column name.
row - the row index.
Throws:
ArrayIndexOutOfBoundsException() - if the index is out of range.

getNameField


public java.lang.Object getNameField()
Identifies a prefered field for naming a record.

setNameField


public void setNameField(java.lang.Object name)
Identifies a prefered field for naming a record.
Parameters:
name - the field name

width


public int width()
The number of columns in the RecordSet.
Returns:
number of columns.

length


public int length()
The number of rows in the RecordSet.
Returns:
number of rows.

clone


public java.lang.Object clone()
Creates a shallow copy of this RecordSet.
Overrides:
clone in class java.lang.Object
Returns:
a new RecordSet

lock


public java.lang.Object lock()

print


public void print()


Comments, suggestions, and bug reports are welcomed and encouraged.
Please refer them to our support page. Thank you.

Copyright © 1999-2001 Produx House, Corp. All rights reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc.