gshute.util
Class ListDictionary

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

public class ListDictionary
extends java.lang.Object
implements Dictionary

A ListDictionary is an implementation of the Dictionary interface using an ArrayList implementation.


Field Summary
protected  java.util.Comparator comparator
          comparator is the comparator for keys in this dictionary.
protected  java.util.ArrayList entries
          entries is the list of entries for this dictionary.
protected  Selector selector
          selector is the keys selector for this dictionary.
 
Constructor Summary
ListDictionary(java.util.Comparator c, Selector s)
          new ListDictionary(c, s) returns a dictionary that uses c as its key comparator and s as its key selector.
 
Method Summary
 void add(java.lang.Object dat)
          dict.add(k, dat) adds an entry with data dat and key k to dict.
protected  int addIndex(java.lang.Object k)
          addIndex(k) returns the index where an entry with key k should be added.
 void clear()
          dict.clear() removes all entries from dict.
 java.lang.Object dataFor(java.lang.Object k)
          dict.dataFor(k) returns the data for key k in dict.
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.
 java.lang.Object getKey(java.lang.Object dat)
          dict.getKey(dat) returns the key that dict uses for dat.
 boolean isKey(java.lang.Object k)
          dict.isKey(k) returns true if there is an entry with key k in dict.
 java.util.Iterator iterator()
          dict.iterator() returns an iterator for all of the entries in dict.
 java.util.Iterator iterator(java.lang.Object kLo)
          dict.iterator(Object kLo) returns an iterator for the entries in dict whose key is at least kLo.
 java.util.Iterator iterator(java.lang.Object kLo, java.lang.Object kHi)
          dict.iterator(Object kLo, Object kHi) returns an iterator for the entries in dict whose key is at least kLo and less than kHi.
 void remove(java.lang.Object k)
          dict.remove(k) removes the entry for key k from dict.
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()
          dict.size() returns the number of entries in dict.
 
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 dictionary.

comparator

protected java.util.Comparator comparator
comparator is the comparator for keys in this dictionary.

selector

protected Selector selector
selector is the keys selector for this dictionary.
Constructor Detail

ListDictionary

public ListDictionary(java.util.Comparator c,
                      Selector s)
new ListDictionary(c, s) returns a dictionary that uses c as its key comparator and s as its key selector.
Method Detail

isKey

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

getKey

public java.lang.Object getKey(java.lang.Object dat)
dict.getKey(dat) returns the key that dict uses for dat.
Specified by:
getKey in interface Dictionary

add

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

Precondition: dict.isKey(k) is false.

Specified by:
add in interface Dictionary

dataFor

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

Precondition: dict.isKey(k) is true.

Specified by:
dataFor in interface Dictionary

remove

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

Precondition: dict.isKey(k) is true.

Specified by:
remove in interface Dictionary

size

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

clear

public void clear()
dict.clear() removes all entries from dict.
Specified by:
clear in interface Dictionary

iterator

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

iterator

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

iterator

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

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.