Class Table

java.lang.Object
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

    Constructors
    Constructor
    Description
    Constructs a new table.
    Table(int rows, int cols)
    Constructs a new table of the specified initial size.
  • Method Summary

    Modifier and Type
    Method
    Description
    get(int row, int col)
    Returns the object at row, col or null if the specified row or col do not exist.
    get(int row, String col)
    Returns the object at row, col or null if the specified row or col do not exist.
    get(String row, int col)
    Returns the object at row, col or null if the specified row or col do not exist.
    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)
     
    put(int row, int col, Object obj)
     
    put(int row, String col, Object obj)
     
    put(String row, int col, Object obj)
     
    put(String row, String col, Object obj)
    Returns the object at row, col or null if the specified row or col do not exist.
     

    Methods inherited from class Object

    equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Table

      public Table()
      Constructs a new table.
    • Table

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

    • 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)