uwcse.collections
Class SimpleListMap

java.lang.Object
  |
  +--uwcse.collections.SimpleListMap
All Implemented Interfaces:
SimpleMap

public class SimpleListMap
extends java.lang.Object
implements SimpleMap

Implementation of the SimpleMap interface via a single SimpleList. A simple, but not efficient implementation. The fundamental operations (get, put, remove) all execute in O(N) time, where N is the number of entries in the table.


Constructor Summary
SimpleListMap()
           
 
Method Summary
 void clear()
          Remove all associations from the map.
 boolean containsKey(java.lang.Object key)
          Answer true iff the given key exists in the map.
 boolean containsValue(java.lang.Object value)
          Answer true iff the given value exists in the map.
 java.lang.Object get(java.lang.Object key)
          Answer the value associated with the given key.
 boolean isEmpty()
          Answer (size() == 0)
 SimpleIterator keys()
          Answer a SimpleIterator over the keys in the association.
static void main(java.lang.String[] args)
           
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associate the given key and value, replacing any previous association for the given key.
 java.lang.Object remove(java.lang.Object key)
          Remove the association (if any) for the given key.
 int size()
          Answer the number of associations in the map.
 java.lang.String toString()
           
 SimpleIterator values()
          Answer a SimpleIterator over the values in the association.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleListMap

public SimpleListMap()
Method Detail

clear

public void clear()
Description copied from interface: SimpleMap
Remove all associations from the map.
Specified by:
clear in interface SimpleMap

containsKey

public boolean containsKey(java.lang.Object key)
Description copied from interface: SimpleMap
Answer true iff the given key exists in the map.
Specified by:
containsKey in interface SimpleMap

containsValue

public boolean containsValue(java.lang.Object value)
Description copied from interface: SimpleMap
Answer true iff the given value exists in the map.
Specified by:
containsValue in interface SimpleMap

get

public java.lang.Object get(java.lang.Object key)
Description copied from interface: SimpleMap
Answer the value associated with the given key.
Specified by:
get in interface SimpleMap
Following copied from interface: uwcse.collections.SimpleMap
Returns:
null if the key is not in the map

isEmpty

public boolean isEmpty()
Description copied from interface: SimpleMap
Answer (size() == 0)
Specified by:
isEmpty in interface SimpleMap

keys

public SimpleIterator keys()
Description copied from interface: SimpleMap
Answer a SimpleIterator over the keys in the association.
Specified by:
keys in interface SimpleMap

main

public static void main(java.lang.String[] args)

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from interface: SimpleMap
Associate the given key and value, replacing any previous association for the given key.
Specified by:
put in interface SimpleMap
Following copied from interface: uwcse.collections.SimpleMap
Returns:
the result of get(key) before the new association is made

remove

public java.lang.Object remove(java.lang.Object key)
Description copied from interface: SimpleMap
Remove the association (if any) for the given key.
Specified by:
remove in interface SimpleMap
Following copied from interface: uwcse.collections.SimpleMap
Returns:
the result of get(key) before the removal takes place

size

public int size()
Description copied from interface: SimpleMap
Answer the number of associations in the map.
Specified by:
size in interface SimpleMap

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

values

public SimpleIterator values()
Description copied from interface: SimpleMap
Answer a SimpleIterator over the values in the association.
Specified by:
values in interface SimpleMap