|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure.AbstractMap<K,V> structure.Table<K,V>
public class Table<K extends java.lang.Comparable<K>,V>
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 = newTable()
; 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
Constructor Summary | |
---|---|
Table()
Construct a new, empty table. |
|
Table(Table other)
|
Method Summary | |
---|---|
void |
clear()
Remove all the elements of the table. |
boolean |
containsKey(K key)
Determine if the key is in the table. |
boolean |
containsValue(V value)
Returns true if the value is associated with some key in the table. |
Set<Association<K,V>> |
entrySet()
Return a structure containing all the entries in this Table |
V |
get(K key)
Retrieve the value associated with the key provided. |
boolean |
isEmpty()
Determine if the table is empty. |
java.util.Iterator<V> |
iterator()
Construct an iterator over the values of the table. |
java.util.Iterator<K> |
keys()
Construct an iterator over the keys of the table. |
Set<K> |
keySet()
Return a set containing the keys referenced by this data structure. |
static void |
main(java.lang.String[] argv)
|
V |
put(K key,
V value)
Enter a key-value pair into the table. |
V |
remove(K key)
Remove a key-value pair, based on key. |
int |
size()
Determine the number of key-value pairs within the table. |
java.lang.String |
toString()
Construct a string representing value of table. |
Structure<V> |
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 |
---|
equals, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface structure.Map |
---|
equals, hashCode, putAll |
Constructor Detail |
---|
public Table()
public Table(Table other)
Method Detail |
---|
public V get(K key)
get
in interface Map<K extends java.lang.Comparable<K>,V>
key
- The key of the key-value pair sought.
public V put(K key, V value)
put
in interface Map<K extends java.lang.Comparable<K>,V>
key
- The unique key in the table.value
- The (possibly null) value associated with key.
public boolean isEmpty()
isEmpty
in interface Map<K extends java.lang.Comparable<K>,V>
public void clear()
clear
in interface Map<K extends java.lang.Comparable<K>,V>
public java.util.Iterator<K> keys()
public java.util.Iterator<V> iterator()
public boolean containsKey(K key)
containsKey
in interface Map<K extends java.lang.Comparable<K>,V>
key
- A non-null key sought in the table.
public boolean containsValue(V value)
containsValue
in interface Map<K extends java.lang.Comparable<K>,V>
value
- The value sought (possibly null).
public V remove(K key)
remove
in interface Map<K extends java.lang.Comparable<K>,V>
key
- The key of the key-value pair to be removed.
public int size()
size
in interface Map<K extends java.lang.Comparable<K>,V>
public Set<K> keySet()
keySet
in interface Map<K extends java.lang.Comparable<K>,V>
public Structure<V> values()
values
in interface Map<K extends java.lang.Comparable<K>,V>
public Set<Association<K,V>> entrySet()
entrySet
in interface Map<K extends java.lang.Comparable<K>,V>
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] argv)
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |