csli.util.collections
Class MapList

java.lang.Object
  extended by csli.util.collections.MapList

public class MapList
extends Object

Implements a both a key-value map and a ordered list of key-value pairs. Ensures correspondence between the two structures.

Author:
Danilo Mirkovic

Constructor Summary
MapList()
           
MapList(List keys, Map kvpairs, boolean ensureEqual)
          Makes a mapList from a list of keys and a map of key-value pairs.
 
Method Summary
 void add(Object key, Object value)
           
 void add(Object key, Object value, int index)
          Puts the key-value pair into the map, an inserts it into the list at the specified position.
 Object get(int index)
          Returns the value at the specified position.
 Object get(Object key)
          Returns the value associated with the key, null if none.
 Object getKey(int index)
          Returns the value at the specified position.
 List getKeyList()
           
 Map getMap()
           
 List getValueList()
           
 boolean put(Object key, Object value)
          Puts the key-value pair into the map.
 Object remove(int index)
          Removes the key and value at index from the list, and the pair from the map.
 Object remove(Object key)
          Removes the key and the associated value from both the map and the lists.
 Object set(int index, Object value)
          Sets the value at the specified position, and changes the assignment in that value in the map as well.
 int size()
          Number of elements in the collection
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MapList

public MapList(List keys,
               Map kvpairs,
               boolean ensureEqual)
Makes a mapList from a list of keys and a map of key-value pairs. Key-value pairs are only placed in if they are in BOTH the keys and kvpairs. If ensureIntegrity is true, throws an exception if the number of keys in all 3 structures is not equal.


MapList

public MapList()
Method Detail

getKeyList

public List getKeyList()

getValueList

public List getValueList()

getMap

public Map getMap()

add

public void add(Object key,
                Object value,
                int index)
Puts the key-value pair into the map, an inserts it into the list at the specified position.

Throws:
IllegalStateException - if the key is already in the map

add

public void add(Object key,
                Object value)

put

public boolean put(Object key,
                   Object value)
Puts the key-value pair into the map. If the key did not yet exist in the map, appends it to the end of the list, retu. If the key existed, replaces the value at the appropriate position in the list.

Returns:
true if key was there (changed the values list), false if not (appended to the keys/values lists)

set

public Object set(int index,
                  Object value)
Sets the value at the specified position, and changes the assignment in that value in the map as well.


remove

public Object remove(Object key)
Removes the key and the associated value from both the map and the lists.


remove

public Object remove(int index)
Removes the key and value at index from the list, and the pair from the map.


getKey

public Object getKey(int index)
Returns the value at the specified position.


get

public Object get(int index)
Returns the value at the specified position.


get

public Object get(Object key)
Returns the value associated with the key, null if none.


size

public int size()
Number of elements in the collection