|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object | +--de.rwth.utils.Table
A class for creating tables consisting of rows and columns. Each column has a field name associated with it and each row has a key name associated with it. The resulting tables can be converted to a String which is suitable for CSV (comma separated values) files.
| Field Summary | |
protected char |
columnsep
The column separator char for the conversion to String. |
protected java.util.LinkedList |
fieldnames
The list of field names. |
protected java.lang.String |
keyname
The field name of the key column. |
protected java.util.HashMap |
keys
Stores the rows of the table. |
protected char |
quotechar
The quote char for the conversion to String. |
protected char |
recordsep
The record separator char for the conversion to String. |
| Constructor Summary | |
Table(java.lang.String keyname)
Creates a new Table instance with default values for record
separator (\n), column separator (,), and quote
character ("). |
|
| Method Summary | |
void |
addNewFieldName(java.lang.String fieldname)
Creates a new column in this table. |
void |
createNewKey(java.lang.String key)
Creates a new row in this table. |
java.lang.Object |
getFieldForKey(java.lang.String fieldname,
java.lang.String key)
Gets the value of a cell for a specific row/column. |
boolean |
hasFieldName(java.lang.String fieldname)
Checks if a String is a valid field name in this table. |
static void |
main(java.lang.String[] args)
Mini test environment. |
protected java.lang.String |
maybequote(java.lang.Object o)
Returns the maybe quoted String representation of its argument. |
void |
setFieldForKey(java.lang.String fieldname,
java.lang.String key,
java.lang.Object value)
Sets the value of a cell for a specific row/column. |
java.lang.String |
toString()
Creates a String representation of this table. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected java.lang.String keyname
protected java.util.LinkedList fieldnames
protected java.util.HashMap keys
HashMap of column entries, which in turn hash a field name to the
value in the cell.protected char recordsep
protected char columnsep
protected char quotechar
| Constructor Detail |
public Table(java.lang.String keyname)
Table instance with default values for record
separator (\n), column separator (,), and quote
character (").keyname - a String value with the name of the key column.| Method Detail |
public boolean hasFieldName(java.lang.String fieldname)
String is a valid field name in this table.fieldname - a String value: The name to check.boolean value: true if and only if the name
was the argument to the constructor of this table, or the argument of one of the
subsequent calls to addNewFieldName.
public void addNewFieldName(java.lang.String fieldname)
throws java.lang.IllegalArgumentException
fieldname - a String valuejava.lang.IllegalArgumentException - if the fieldname is already one
of the field names or the name of the key column.
public void createNewKey(java.lang.String key)
throws java.lang.IllegalArgumentException
key - a String valuejava.lang.IllegalArgumentException - if there is already a row with
key.
public void setFieldForKey(java.lang.String fieldname,
java.lang.String key,
java.lang.Object value)
throws java.lang.IllegalArgumentException
fieldname - a String value: The column of the cell.key - a String value: The row of the cell.value - an Object valuejava.lang.IllegalArgumentException - if either row or column do not exist or if
there is already a value for this cell.
public java.lang.Object getFieldForKey(java.lang.String fieldname,
java.lang.String key)
fieldname - a String value: The column of the cell.key - a String value: The row of the cell.Object value: The valuejava.lang.IllegalArgumentException - if either row or column do not exist or if
there is no value associated with this cell.protected java.lang.String maybequote(java.lang.Object o)
o - an Object valueString valuepublic java.lang.String toString()
String representation of this table. Rows are separated
with the record separator and columns with a column separator. The first row
contains the field names. In each row, the first entry is the key of the row,
followed by string representations of the values obtained by
toString(). The order of rows and keys is undetermined. If the
string representation of a value contains the column separator or blanks at the
beginning or end, it is enclosed in quotes and quotes inside are doubled.toString in class java.lang.ObjectString valuepublic static void main(java.lang.String[] args)
args - a String[] value
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||