org.mortbay.util
Class MultiMap

java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap
          extended by org.mortbay.util.MultiMap
All Implemented Interfaces:
Serializable, Cloneable, Map
Direct Known Subclasses:
UrlEncoded

public class MultiMap
extends HashMap
implements Cloneable

A multi valued Map. This Map specializes HashMap and provides methods that operate on multi valued items.

Implemented as a map of LazyList values

Author:
Greg Wilkins (gregw)
See Also:
LazyList, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
MultiMap()
          Constructor.
MultiMap(int size)
          Constructor.
MultiMap(Map map)
          Constructor.
 
Method Summary
 void add(Object name, Object value)
          Add value to multi valued entry.
 void addValues(Object name, List values)
          Add values to multi valued entry.
 void addValues(Object name, String[] values)
          Add values to multi valued entry.
 Object clone()
           
 Object get(Object name)
           
 String getString(Object name)
          Get value as String.
 Object getValue(Object name, int i)
          Get a value from a multiple value.
 List getValues(Object name)
          Get multiple values.
 Object put(Object name, Object value)
          Put and entry into the map.
 void putAll(Map m)
          Put all contents of map.
 Object putValues(Object name, List values)
          Put multi valued entry.
 Object putValues(Object name, String[] values)
          Put multi valued entry.
 boolean removeValue(Object name, Object value)
          Remove value.
 Map toStringArrayMap()
           
 
Methods inherited from class java.util.HashMap
clear, containsKey, containsValue, entrySet, isEmpty, keySet, remove, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

MultiMap

public MultiMap()
Constructor.


MultiMap

public MultiMap(int size)
Constructor.

Parameters:
size - Capacity of the map

MultiMap

public MultiMap(Map map)
Constructor.

Parameters:
map -
Method Detail

getValues

public List getValues(Object name)
Get multiple values. Single valued entries are converted to singleton lists.

Parameters:
name - The entry key.
Returns:
Unmodifieable List of values.

getValue

public Object getValue(Object name,
                       int i)
Get a value from a multiple value. If the value is not a multivalue, then index 0 retrieves the value or null.

Parameters:
name - The entry key.
i - Index of element to get.
Returns:
Unmodifieable List of values.

getString

public String getString(Object name)
Get value as String. Single valued items are converted to a String with the toString() Object method. Multi valued entries are converted to a comma separated List. No quoting of commas within values is performed.

Parameters:
name - The entry key.
Returns:
String value.

get

public Object get(Object name)
Specified by:
get in interface Map
Overrides:
get in class HashMap

put

public Object put(Object name,
                  Object value)
Put and entry into the map.

Specified by:
put in interface Map
Overrides:
put in class HashMap
Parameters:
name - The entry key.
value - The entry value.
Returns:
The previous value or null.

putValues

public Object putValues(Object name,
                        List values)
Put multi valued entry.

Parameters:
name - The entry key.
values - The List of multiple values.
Returns:
The previous value or null.

putValues

public Object putValues(Object name,
                        String[] values)
Put multi valued entry.

Parameters:
name - The entry key.
values - The String array of multiple values.
Returns:
The previous value or null.

add

public void add(Object name,
                Object value)
Add value to multi valued entry. If the entry is single valued, it is converted to the first value of a multi valued entry.

Parameters:
name - The entry key.
value - The entry value.

addValues

public void addValues(Object name,
                      List values)
Add values to multi valued entry. If the entry is single valued, it is converted to the first value of a multi valued entry.

Parameters:
name - The entry key.
values - The List of multiple values.

addValues

public void addValues(Object name,
                      String[] values)
Add values to multi valued entry. If the entry is single valued, it is converted to the first value of a multi valued entry.

Parameters:
name - The entry key.
values - The String array of multiple values.

removeValue

public boolean removeValue(Object name,
                           Object value)
Remove value.

Parameters:
name - The entry key.
value - The entry value.
Returns:
true if it was removed.

putAll

public void putAll(Map m)
Put all contents of map.

Specified by:
putAll in interface Map
Overrides:
putAll in class HashMap
Parameters:
m - Map

toStringArrayMap

public Map toStringArrayMap()
Returns:
Map of String arrays

clone

public Object clone()
Overrides:
clone in class HashMap