gshute.util
Class ListTable

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

public class ListTable
extends java.lang.Object
implements Table

A ListTable is an implementation of the Table interface using an ArrayList implementation.


Field Summary
protected  java.util.Comparator comparator
          comparator is the comparator for keys in this table.
protected  java.util.ArrayList entries
          entries is the list of entries for this table.
 
Constructor Summary
ListTable(java.util.Comparator c)
          new ListTable(c) returns a table that uses c as its key comparator.
 
Method Summary
 void add(java.lang.Object k, java.lang.Object dat)
          tbl.add(k, dat) adds an entry with data dat and key k to tbl.
protected  int addIndex(java.lang.Object k)
          addIndex(k) returns the index where an entry with key k should be added.
 void clear()
          tbl.clear() removes all entries from tbl.
 java.lang.Object data(java.lang.Object k)
          tbl.data(k) returns the data for key k in tbl.
protected  int geqIndex(java.lang.Object k)
          geqIndex(k) returns the index of the first entry with key greater than or equal to k or entries.size() if there is no such entry.
 boolean isKey(java.lang.Object k)
          tbl.isKey(k) returns true if there is an entry with key k in tbl.
 java.util.Iterator iterator()
          tbl.iterator() returns an iterator for all of the entries in tbl.
 java.util.Iterator iterator(java.lang.Object kLo)
          tbl.iterator(Object kLo) returns an iterator for the entries in tbl whose key is at least kLo.
 java.util.Iterator iterator(java.lang.Object kLo, java.lang.Object kHi)
          tbl.iterator(Object kLo, Object kHi) returns an iterator for the entries in tbl whose key is at least kLo and less than kHi.
 void remove(java.lang.Object k)
          tbl.remove(k) removes the entry for key k from tbl.
protected  int searchIndex(java.lang.Object k)
          searchIndex(k) returns the index of the entry with key k or -1 if it does not exist.
 int size()
          tbl.size() returns the number of entries in tbl.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entries

protected java.util.ArrayList entries
entries is the list of entries for this table.

comparator

protected java.util.Comparator comparator
comparator is the comparator for keys in this table.
Constructor Detail

ListTable

public ListTable(java.util.Comparator c)
new ListTable(c) returns a table that uses c as its key comparator.
Method Detail

isKey

public boolean isKey(java.lang.Object k)
tbl.isKey(k) returns true if there is an entry with key k in tbl.
Specified by:
isKey in interface Table

add

public void add(java.lang.Object k,
                java.lang.Object dat)
tbl.add(k, dat) adds an entry with data dat and key k to tbl.

Precondition: tbl.isKey(k) is false.

Specified by:
add in interface Table

data

public java.lang.Object data(java.lang.Object k)
tbl.data(k) returns the data for key k in tbl.

Precondition: tbl.isKey(k) is true.

Specified by:
data in interface Table

remove

public void remove(java.lang.Object k)
tbl.remove(k) removes the entry for key k from tbl.

Precondition: tbl.isKey(k) is true.

Specified by:
remove in interface Table

size

public int size()
tbl.size() returns the number of entries in tbl.
Specified by:
size in interface Table

clear

public void clear()
tbl.clear() removes all entries from tbl.
Specified by:
clear in interface Table

iterator

public java.util.Iterator iterator()
tbl.iterator() returns an iterator for all of the entries in tbl.
Specified by:
iterator in interface Table

iterator

public java.util.Iterator iterator(java.lang.Object kLo)
tbl.iterator(Object kLo) returns an iterator for the entries in tbl whose key is at least kLo.
Specified by:
iterator in interface Table

iterator

public java.util.Iterator iterator(java.lang.Object kLo,
                                   java.lang.Object kHi)
tbl.iterator(Object kLo, Object kHi) returns an iterator for the entries in tbl whose key is at least kLo and less than kHi.
Specified by:
iterator in interface Table

addIndex

protected int addIndex(java.lang.Object k)
addIndex(k) returns the index where an entry with key k should be added.

searchIndex

protected int searchIndex(java.lang.Object k)
searchIndex(k) returns the index of the entry with key k or -1 if it does not exist.

geqIndex

protected int geqIndex(java.lang.Object k)
geqIndex(k) returns the index of the first entry with key greater than or equal to k or entries.size() if there is no such entry.