scale.common
Class Table<K,V>

java.lang.Object
  extended by scale.common.Table<K,V>

public class Table<K,V>
extends java.lang.Object

This class defines a table structure that is used to record various pieces of information.

$Id: Table.java,v 1.27 2006-08-18 21:54:37 burrill Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

The table has a very simple structure: a HashMap points to HashSets which point to individual objects.

The table is optimized to not create a HashSet for a row if the row contains just one element. This means that the elements of a row can not be declarted as HashSets.

See Also:
HashMap, HashSet

Constructor Summary
Table()
           
Table(int capacity)
           
Table(Table<K,V> old)
           
 
Method Summary
 boolean add(K key, V value)
          This method adds a new object into the table.
 void add(Table<K,V> old)
          This method adds a table to this table.
 void clear()
          Empty the table.
 boolean contains(java.lang.Object value)
          Return true if the value is contained in the Table.
 boolean containsValue(java.lang.Object value)
          Return true if the value is contained in the Table.
 java.util.Enumeration<V> elements()
          Return an enumeration of all the elements of this Table.
 V get(K key, V value)
          This method determines if an object is already in the table.
 java.lang.Object[] getRowArray(K key)
          Return an array of the objects in a row.
 java.util.Iterator<V> getRowEnumeration(K key)
          Return an iteration of the objects in a row.
 HashSet<V> getRowSet(K key)
          Return a HashSet of the objects in a row.
 boolean isRowEmpty(K key)
          Return true if the row is empty.
 java.util.Enumeration<K> keys()
          Return an enumeration of the row key value.
 int numRows()
          Return the number of rows of the table.
 java.lang.Object put(K key, V value)
          This method adds a new object into the table.
 void remove(HashSet<V> values)
          Remove the set of values from the table.
 java.lang.Object remove(K key, V value)
          This method removes an object from the table.
 V remove(java.lang.Object value)
          Remove this value from the table.
 void removeRow(K key)
          This methhod removes an entire row from the table.
 boolean rowContains(K key, java.lang.Object value)
          Return true if the row contains the value.
 int rowSize(K key)
          Return the number of elements in a row of this Table.
 int size()
          Return the number of elements in this Table.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Table

public Table()

Table

public Table(int capacity)

Table

public Table(Table<K,V> old)
Method Detail

clear

public void clear()
Empty the table.


add

public void add(Table<K,V> old)
This method adds a table to this table.


add

public boolean add(K key,
                   V value)
This method adds a new object into the table.

Parameters:
key - is the row index
value - is the column index (it may not be a HashSet)
Returns:
true if the value was not already in the Table

put

public java.lang.Object put(K key,
                            V value)
This method adds a new object into the table.

Parameters:
key - is the row index
value - is the column index (it may not be a HashSet)
Returns:
null

get

public V get(K key,
             V value)
This method determines if an object is already in the table.

Parameters:
key - is the row index
value - is the column index (it may not be a HashSet)
Returns:
the object if it is in the table or null.

getRowArray

public java.lang.Object[] getRowArray(K key)
Return an array of the objects in a row.

Parameters:
key - the row index

getRowSet

public HashSet<V> getRowSet(K key)
Return a HashSet of the objects in a row.

Parameters:
key - the row index

rowContains

public boolean rowContains(K key,
                           java.lang.Object value)
Return true if the row contains the value. Uses the equals() method.


isRowEmpty

public boolean isRowEmpty(K key)
Return true if the row is empty.

Parameters:
key - the row index

getRowEnumeration

public java.util.Iterator<V> getRowEnumeration(K key)
Return an iteration of the objects in a row.

Parameters:
key - the row index

removeRow

public void removeRow(K key)
This methhod removes an entire row from the table.

Parameters:
key - the row index

remove

public java.lang.Object remove(K key,
                               V value)
This method removes an object from the table.

Parameters:
key - is the row index
value - is the column index
Returns:
the value if the value was in the row, otherwise null

keys

public java.util.Enumeration<K> keys()
Return an enumeration of the row key value.


numRows

public int numRows()
Return the number of rows of the table.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

elements

public java.util.Enumeration<V> elements()
Return an enumeration of all the elements of this Table.


contains

public boolean contains(java.lang.Object value)
Return true if the value is contained in the Table.


containsValue

public boolean containsValue(java.lang.Object value)
Return true if the value is contained in the Table.


rowSize

public int rowSize(K key)
Return the number of elements in a row of this Table.


size

public int size()
Return the number of elements in this Table.


remove

public V remove(java.lang.Object value)
Remove this value from the table. This method is slow and should be avoided.

Returns:
null if the value was not in the table or the value otherwise.

remove

public void remove(HashSet<V> values)
Remove the set of values from the table. This method is slow and should be avoided.