structure
Class MapList

java.lang.Object
  |
  +--structure.MapList
All Implemented Interfaces:
Map

public class MapList
extends java.lang.Object
implements Map

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 = new MapList();
	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);
 }
 


Field Summary
protected  List data
          List for storing the entries in this map
 
Constructor Summary
MapList()
          Construct an empty map, based on a list
MapList(Map source)
          Construct a map with values found in source
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object k)
           
 boolean containsValue(java.lang.Object v)
           
 Set entrySet()
           
 boolean equals(java.lang.Object other)
           
 java.lang.Object get(java.lang.Object k)
           
 int hashCode()
           
 boolean isEmpty()
           
 Set keySet()
           
 java.lang.Object put(java.lang.Object k, java.lang.Object v)
           
 void putAll(Map other)
           
 java.lang.Object remove(java.lang.Object k)
           
 int size()
          Returns the number of entries in the map
 Structure values()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

data

protected List data
List for storing the entries in this map

Constructor Detail

MapList

public MapList()
Construct an empty map, based on a list


MapList

public MapList(Map source)
Construct a map with values found in source

Method Detail

size

public int size()
Returns the number of entries in the map

Specified by:
size in interface Map

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map

containsKey

public boolean containsKey(java.lang.Object k)
Specified by:
containsKey in interface Map

containsValue

public boolean containsValue(java.lang.Object v)
Specified by:
containsValue in interface Map

get

public java.lang.Object get(java.lang.Object k)
Specified by:
get in interface Map

put

public java.lang.Object put(java.lang.Object k,
                            java.lang.Object v)
Specified by:
put in interface Map

remove

public java.lang.Object remove(java.lang.Object k)
Specified by:
remove in interface Map

putAll

public void putAll(Map other)
Specified by:
putAll in interface Map

clear

public void clear()
Specified by:
clear in interface Map

keySet

public Set keySet()
Specified by:
keySet in interface Map

values

public Structure values()
Specified by:
values in interface Map

entrySet

public Set entrySet()
Specified by:
entrySet in interface Map

equals

public boolean equals(java.lang.Object other)
Specified by:
equals in interface Map
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Specified by:
hashCode in interface Map
Overrides:
hashCode in class java.lang.Object