|
© 1998-2002 McGraw-Hill | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object
|
+--structure.AbstractMap
|
+--structure.Table
An implementation of an ordered dictionary. Key-value pairs are kept in the structure in order. To accomplish this, the keys of the table must be comparable.
Example Usage:
To create an alphebetized dictionary by reading a collection of words and definitions from System.in we could use the following:
public static void main (String[] argv){
OrderedMap dict = new Table();
ReadStream r = new ReadStream();
String word, def;
System.out.println("Enter a word: ");
while(!r.eof()){
word = r.readLine();
System.out.println("Enter a definition: ");
def = r.readLine();
dict.put(word,def);
System.out.println("Enter a word: ");
}
System.out.println(dict);
}
Comparable| Field Summary | |
protected OrderedStructure |
data
An ordered structure that maintains the ComparableAssociations that store the key-value pairings. |
| Constructor Summary | |
Table()
Construct a new, empty table. |
|
Table(Table other)
|
|
| Method Summary | |
void |
clear()
Remove all the elements of the table. |
boolean |
containsKey(Object key)
Determine if the key is in the table. |
boolean |
containsValue(Object value)
Returns true if the value is associated with some key in the table. |
Set |
entrySet()
Return a structure containing all the entries in this Table |
Object |
get(Object key)
Retrieve the value associated with the key provided. |
boolean |
isEmpty()
Determine if the table is empty. |
Iterator |
iterator()
Construct an iterator over the values of the table. |
Iterator |
keys()
Construct an iterator over the keys of the table. |
Set |
keySet()
Return a set containing the keys referenced by this data structure. |
static void |
main(String[] argv)
|
Object |
put(Object key,
Object value)
Enter a key-value pair into the table. |
Object |
remove(Object key)
Remove a key-value pair, based on key. |
int |
size()
Determine the number of key-value pairs within the table. |
String |
toString()
Construct a string representing value of table. |
Structure |
values()
Return a structure containing all the values referenced by this data structure. |
| Methods inherited from class structure.AbstractMap |
hashCode, putAll |
| Methods inherited from class java.lang.Object |
|
| Methods inherited from interface structure.Map |
equals, hashCode, putAll |
| Field Detail |
protected OrderedStructure data
| Constructor Detail |
public Table()
public Table(Table other)
| Method Detail |
public Object get(Object key)
get in interface Mapkey - The key of the key-value pair sought.
public Object put(Object key,
Object value)
put in interface Mapkey - The unique key in the table.value - The (possibly null) value associated with key.public boolean isEmpty()
isEmpty in interface Mappublic void clear()
clear in interface Mappublic Iterator keys()
public Iterator iterator()
public boolean containsKey(Object key)
containsKey in interface Mapkey - A non-null key sought in the table.public boolean containsValue(Object value)
containsValue in interface Mapvalue - The value sought (possibly null).public Object remove(Object key)
remove in interface Mapkey - The key of the key-value pair to be removed.public int size()
size in interface Mappublic Set keySet()
keySet in interface Mappublic Structure values()
values in interface Mappublic Set entrySet()
entrySet in interface Mappublic String toString()
toString in class Objectpublic static void main(String[] argv)
|
© 1998-2002 McGraw-Hill | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||