structure5
Interface Map<K,V>

All Known Subinterfaces:
OrderedMap<K,V>
All Known Implementing Classes:
AbstractMap, ChainedHashtable, Hashtable, MapList, Table

public interface Map<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.

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 = new structure.MapBST#MapBST();
      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);
 }
 


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()
           
 Structure<V> values()
           
 

Method Detail

size

int size()
Postcondition:
returns the number of entries in the map

isEmpty

boolean isEmpty()
Postcondition:
returns true iff this map does not contain any entries

containsKey

boolean containsKey(K k)
Precondition:
k is non-null
Postcondition:
returns true iff k is in the domain of the map

containsValue

boolean containsValue(V v)
Precondition:
v is non-null
Postcondition:
returns true iff v is the target of at least one map entry; that is, v is in the range of the map

get

V get(K k)
Precondition:
k is a key, possibly in the map
Postcondition:
returns the value mapped to from k, or null

put

V put(K k,
      V v)
Precondition:
k and v are non-null
Postcondition:
inserts a mapping from k to v in the map

remove

V remove(K k)
Precondition:
k is non-null
Postcondition:
removes any mapping from k to a value, from the mapping

putAll

void putAll(Map<K,V> other)
Precondition:
other is non-null
Postcondition:
all the mappings of other are installed in this map, overriding any conflicting maps

clear

void clear()
Postcondition:
removes all map entries associated with this map

keySet

Set<K> keySet()
Postcondition:
returns a set of all keys associated with this map

values

Structure<V> values()
Postcondition:
returns a structure that contains the range of the map

entrySet

Set<Association<K,V>> entrySet()
Postcondition:
returns a set of (key-value) pairs, generated from this map

equals

boolean equals(java.lang.Object other)
Overrides:
equals in class java.lang.Object
Precondition:
other is non-null
Postcondition:
returns true iff maps this and other are entry-wise equal

hashCode

int hashCode()
Overrides:
hashCode in class java.lang.Object
Postcondition:
returns a hash code associated with this structure