fc.util
Class Table

java.lang.Object
  extended by fc.util.Table

public final class Table
extends Object

Implements a simple table data structure. Like a 2D array but uses nested hash tables to get (row, col) based on a (name, name) pair. The table grows automatically as needed.

Differs from a 2D Object[][] in that names can be used instead of indices.

All indexes are internally strings. When adding or retrieving values, either numerical and string indices can be specified for either row or col when retrieving a (row,col) value. A numerical index is converted into a string value so if one puts a value at (3, 5), that can later be retrieved as ("3", "5") if desired.

Thread safety: This data structure is fully thread safe.


Constructor Summary
Table()
          Constructs a new table.
Table(int rows, int cols)
          Constructs a new table of the specified initial size.
 
Method Summary
 Object get(int row, int col)
          Returns the object at row, col or null if the specified row or col do not exist.
 Object get(int row, String col)
          Returns the object at row, col or null if the specified row or col do not exist.
 Object get(String row, int col)
          Returns the object at row, col or null if the specified row or col do not exist.
 Object get(String row, String col)
          Returns the object at row, col or null if the specified row or col do not exist.
static void main(String[] args)
           
 Object put(int row, int col, Object obj)
           
 Object put(int row, String col, Object obj)
           
 Object put(String row, int col, Object obj)
           
 Object put(String row, String col, Object obj)
          Returns the object at row, col or null if the specified row or col do not exist.
 String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Table

public Table()
Constructs a new table.


Table

public Table(int rows,
             int cols)
Constructs a new table of the specified initial size.

Method Detail

get

public Object get(String row,
                  String col)
Returns the object at row, col or null if the specified row or col do not exist.


get

public Object get(int row,
                  String col)
Returns the object at row, col or null if the specified row or col do not exist.


get

public Object get(String row,
                  int col)
Returns the object at row, col or null if the specified row or col do not exist.


get

public Object get(int row,
                  int col)
Returns the object at row, col or null if the specified row or col do not exist.


put

public Object put(String row,
                  String col,
                  Object obj)
Returns the object at row, col or null if the specified row or col do not exist.

Returns:
the old object at that (row, col) if it exists

put

public Object put(int row,
                  String col,
                  Object obj)

put

public Object put(String row,
                  int col,
                  Object obj)

put

public Object put(int row,
                  int col,
                  Object obj)

toString

public String toString()
Overrides:
toString in class Object

main

public static void main(String[] args)