org.mortbay.util

Class MultiMap

Implemented Interfaces:
Cloneable
Known Direct 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

Version:
$Id: MultiMap.java,v 1.18 2004/12/15 02:13:51 gregwilkins Exp $
Author:
Greg Wilkins (gregw)
See Also:
LazyList

Constructor Summary

MultiMap()
Constructor.
MultiMap(Map map)
Constructor.
MultiMap(int size)
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()

Constructor Details

MultiMap

public MultiMap()
Constructor.

MultiMap

public MultiMap(Map map)
Constructor.
Parameters:
map -

MultiMap

public MultiMap(int size)
Constructor.
Parameters:
size - Capacity of the map

Method Details

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.

clone

public Object clone()

get

public Object get(Object name)

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.

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.

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.

put

public Object put(Object name,
                  Object value)
Put and entry into the map.
Parameters:
name - The entry key.
value - The entry value.
Returns:
The previous value or null.

putAll

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

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.

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.

toStringArrayMap

public Map toStringArrayMap()
Returns:
Map of String arrays

Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.