org.mortbay.util
Class MultiMap

java.lang.Object
  |
  +--java.util.AbstractMap
        |
        +--java.util.HashMap
              |
              +--org.mortbay.util.MultiMap
All Implemented Interfaces:
java.lang.Cloneable, java.util.Map, java.io.Serializable
Direct Known Subclasses:
UrlEncoded

public class MultiMap
extends java.util.HashMap
implements java.lang.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

Version:
$Id: MultiMap.java,v 1.11.2.1 2004/03/16 17:58:01 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
LazyList, Serialized Form

Constructor Summary
MultiMap()
          Constructor.
MultiMap(int size)
          Constructor.
MultiMap(java.util.Map map)
          Constructor.
 
Method Summary
 void add(java.lang.Object name, java.lang.Object value)
          Add value to multi valued entry.
 void addValues(java.lang.Object name, java.util.List values)
          Add values to multi valued entry.
 void addValues(java.lang.Object name, java.lang.String[] values)
          Add values to multi valued entry.
 java.lang.Object clone()
           
 java.lang.Object get(java.lang.Object name)
           
 java.lang.String getString(java.lang.Object name)
          Get value as String.
 java.lang.Object getValue(java.lang.Object name, int i)
          Get a value from a multiple value.
 java.util.List getValues(java.lang.Object name)
          Get multiple values.
 java.lang.Object put(java.lang.Object name, java.lang.Object value)
          Put and entry into the map.
 void putAll(java.util.Map m)
          Put all contents of map.
 java.lang.Object putValues(java.lang.Object name, java.util.List values)
          Put multi valued entry.
 java.lang.Object putValues(java.lang.Object name, java.lang.String[] values)
          Put multi valued entry.
 boolean removeValue(java.lang.Object name, java.lang.Object value)
          Remove value.
 java.util.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
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(java.util.Map map)
Constructor.

Parameters:
map -
Method Detail

getValues

public java.util.List getValues(java.lang.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 java.lang.Object getValue(java.lang.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 java.lang.String getString(java.lang.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 java.lang.Object get(java.lang.Object name)
Specified by:
get in interface java.util.Map
Overrides:
get in class java.util.HashMap

put

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

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

putValues

public java.lang.Object putValues(java.lang.Object name,
                                  java.util.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 java.lang.Object putValues(java.lang.Object name,
                                  java.lang.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(java.lang.Object name,
                java.lang.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(java.lang.Object name,
                      java.util.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(java.lang.Object name,
                      java.lang.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(java.lang.Object name,
                           java.lang.Object value)
Remove value.

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

putAll

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

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

toStringArrayMap

public java.util.Map toStringArrayMap()
Returns:
Map of String arrays

clone

public java.lang.Object clone()
Overrides:
clone in class java.util.HashMap


Copyright ? 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.