|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object structure.MapList<K,V>
public class MapList<K,V>
Associations establish a link between a key and a value. An associative array or map is a structure that allows a disjoint set of keys to become associated with an arbitrary set of values. The convenience of an associative array is that the values used to index the elements need not be comparable and their range need not be known ahead of time. Furthermore, there is no upper bound on the size of the structure. It is able to maintain an arbitrary number of different pieces of information simultaneously. Maps are sometimes called dictionaries because of the uniqueness of the association of words and definitions in a household dictionary.
This implementation is based on a list, so performance for most operations is linear.
Example Usage:
To create a dictionary by reading a collection of words and definitions from System.in we could use the following!
public static void main (String[] argv){ Map dict = newMapList()
; 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); }
Constructor Summary | |
---|---|
MapList()
Construct an empty map, based on a list |
|
MapList(Map<K,V> source)
Construct a map with values found in source |
Method Summary | |
---|---|
void |
clear()
|
boolean |
containsKey(K k)
|
boolean |
containsValue(V v)
|
Set<Association<K,V>> |
entrySet()
|
boolean |
equals(java.lang.Object other)
|
V |
get(K k)
|
int |
hashCode()
|
boolean |
isEmpty()
|
Set<K> |
keySet()
|
V |
put(K k,
V v)
|
void |
putAll(Map<K,V> other)
|
V |
remove(K k)
|
int |
size()
Returns the number of entries in the map |
Structure<V> |
values()
|
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MapList()
public MapList(Map<K,V> source)
Method Detail |
---|
public int size()
size
in interface Map<K,V>
public boolean isEmpty()
isEmpty
in interface Map<K,V>
public boolean containsKey(K k)
containsKey
in interface Map<K,V>
public boolean containsValue(V v)
containsValue
in interface Map<K,V>
public V get(K k)
get
in interface Map<K,V>
public V put(K k, V v)
put
in interface Map<K,V>
public V remove(K k)
remove
in interface Map<K,V>
public void putAll(Map<K,V> other)
putAll
in interface Map<K,V>
public void clear()
clear
in interface Map<K,V>
public Set<K> keySet()
keySet
in interface Map<K,V>
public Structure<V> values()
values
in interface Map<K,V>
public Set<Association<K,V>> entrySet()
entrySet
in interface Map<K,V>
public boolean equals(java.lang.Object other)
equals
in interface Map<K,V>
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface Map<K,V>
hashCode
in class java.lang.Object
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |