Class AssociationList

java.lang.Object
  extended byjava.util.AbstractMap
      extended byAssociationList
All Implemented Interfaces:
java.util.Map
Direct Known Subclasses:
BindingSet, FeatureSet

public class AssociationList
extends java.util.AbstractMap
implements java.util.Map

An AssociationList (or ``alist'') represents a set of values indexed by keys, and so implements the Map interface. The difference is that AssociationList is implemented using a LinkedList of the key-value pairs. One could use a HashMap, but the overhead would probably be higher for small alists.


Nested Class Summary
 
Nested classes inherited from class java.util.AbstractMap
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
(package private)  java.util.LinkedList entries
          LinkedList to hold entries in AssociationList.
 
Fields inherited from class java.util.AbstractMap
 
Constructor Summary
AssociationList()
          Creates a new empty AssociationList.
AssociationList(java.util.Collection c)
          Creates a new AssociationList with the same contents as the given Collection.
 
Method Summary
 java.util.Set entrySet()
          Returns a set view of the mappings contained in this map.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Associates the specified value with the specified key in this map.
 
Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, toString, values
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
clear, containsKey, containsValue, equals, get, hashCode, isEmpty, keySet, putAll, remove, size, values
 

Field Detail

entries

java.util.LinkedList entries
LinkedList to hold entries in AssociationList.

Constructor Detail

AssociationList

public AssociationList()
Creates a new empty AssociationList. This constructor is required by the conventions of the Collection interface.


AssociationList

public AssociationList(java.util.Collection c)
Creates a new AssociationList with the same contents as the given Collection. This constructor is required by the conventions of the Collection interface.

Method Detail

entrySet

public java.util.Set entrySet()
Returns a set view of the mappings contained in this map.
This implementation returns a LinkedListSet whose elements consist of OrderedPair's.

Specified by:
entrySet in interface java.util.Map

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Associates the specified value with the specified key in this map.
This is equivalent to the Lisp form: (setq LIST (cons (cons KEY VALUE) LIST)) or the shorthand using ACONS.
Implementation note: Technically (in Lisp), an alist does not need to check for the prior presence of an entry for a given key, since the way items are looked up (by ASSOC) guarantees that only the most recently added entry will be returned. However, since we are implementing the full Map interface, we need to be more careful to avoid problems with access through iterators and the like (note that this would also be a problem if one used MAPCAR and the like on an alist).
Another technical implementation note is that by using MapEntry.setValue() on the existing entry (if there is one), we modify the entry in a way that might be visible to other code (like using (SETF CDR) rather than ACONS in Lisp).

Specified by:
put in interface java.util.Map