gshute.util
Class DatabaseTable

java.lang.Object
  |
  +--gshute.util.DatabaseTable

public class DatabaseTable
extends java.lang.Object

A DatabaseTable is a poor-person's table in a database.

All tables are in separate files. The first row in the file contains the names of the table columns separated by colons. The remaining lines contain values for rows separated by colons. The number of values in each row should be the same as the number of table columns.


Inner Class Summary
 class DatabaseTable.Row
          A Row provides access to the data in a row of a database table.
 
Field Summary
protected  java.util.List columns
           
protected  java.lang.String keyColumnName
           
protected  java.util.List rows
           
 
Constructor Summary
DatabaseTable(java.lang.String tn)
          new DatabaseTable(tn) returns a database connection to the table named tn.
 
Method Summary
protected  int columnIndex(java.lang.String n)
          columnIndex(n) returns the index in columns of the column whose name is n.
 java.util.Iterator columnNames()
          dbt.columnNames(n) returns an iterator for the column names of dbt.
 DatabaseTable.Row getRow(java.lang.String k)
          dbt.getRow(k) returns the table row whose key (first column) is k, or null if there is no such row.
 java.util.Iterator getRows()
          dbt.getRows() returns an iterator for all of the table rows in dbt.
 java.util.Iterator getRows(java.lang.String col, java.lang.String val)
          dbt.getRows(col, val) returns an iterator for the table rows whose value in the column named col is val.
 java.util.Iterator getValues(java.lang.String col1, java.lang.String col2, java.lang.String val)
          dbt.getValues(col1, col2, val) returns an iterator for the values in col1 of dbt for rows whose value in the column named col2 is val.
 boolean isColumnName(java.lang.String n)
          dbt.isColumnName(n) returns true if n is the name of a column in dbt.
protected  void processData(java.lang.String dat)
           
protected  void processHeader(java.lang.String hdr)
           
protected  int rowIndex(java.lang.String k)
          rowIndex(k) returns the index in rows of the entry whose key is k.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rows

protected java.util.List rows

columns

protected java.util.List columns

keyColumnName

protected java.lang.String keyColumnName
Constructor Detail

DatabaseTable

public DatabaseTable(java.lang.String tn)
new DatabaseTable(tn) returns a database connection to the table named tn.
Method Detail

isColumnName

public boolean isColumnName(java.lang.String n)
dbt.isColumnName(n) returns true if n is the name of a column in dbt.

columnNames

public java.util.Iterator columnNames()
dbt.columnNames(n) returns an iterator for the column names of dbt.

getRow

public DatabaseTable.Row getRow(java.lang.String k)
dbt.getRow(k) returns the table row whose key (first column) is k, or null if there is no such row.

getRows

public java.util.Iterator getRows()
dbt.getRows() returns an iterator for all of the table rows in dbt.

getRows

public java.util.Iterator getRows(java.lang.String col,
                                  java.lang.String val)
dbt.getRows(col, val) returns an iterator for the table rows whose value in the column named col is val.

Preconditions: isColumnName(col) is true.


getValues

public java.util.Iterator getValues(java.lang.String col1,
                                    java.lang.String col2,
                                    java.lang.String val)
dbt.getValues(col1, col2, val) returns an iterator for the values in col1 of dbt for rows whose value in the column named col2 is val. This method emulates a simple join in a relational database.

Preconditions: isColumnName(col1) is true. isColumnName(col2) is true.


rowIndex

protected int rowIndex(java.lang.String k)
rowIndex(k) returns the index in rows of the entry whose key is k. If there is no such entry then rowIndex(k) returns -1.

columnIndex

protected int columnIndex(java.lang.String n)
columnIndex(n) returns the index in columns of the column whose name is n. If there is no such column then columnIndex(n) returns -1.

processHeader

protected void processHeader(java.lang.String hdr)

processData

protected void processData(java.lang.String dat)