Top Description Constructors Methods
org.mortbay.util

public Class MultiMap

extends HashMap
implements Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable
Known Direct Subclasses
org.mortbay.util.UrlEncoded
Imports
java.util.Arrays, .HashMap, .Iterator, .List, .Map

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

Constructor Summary

AccessConstructor and Description
public
MultiMap()

Constructor.

public
MultiMap(int
Capacity of the map
size
)

Constructor.

public
MultiMap(Map<K, V> map)

Constructor.

Method Summary

Modifier and TypeMethod and Description
public void
add(Object
The entry key.
name
,
Object
The entry value.
value
)

Add value to multi valued entry.

public void
addValues(Object
The entry key.
name
,
List<E>
The List of multiple values.
values
)

Add values to multi valued entry.

public void
addValues(Object
The entry key.
name
,
String[]
The String array of multiple values.
values
)

Add values to multi valued entry.

public Object
clone()

Overrides java.util.HashMap.clone.

Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned.
public Object
get(Object
the key whose associated value is to be returned
name
)

Overrides java.util.HashMap.get.

Implements java.util.Map.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.
public String

Returns:

String value.
getString
(Object
The entry key.
name
)

Get value as String.

public Object

Returns:

Unmodifieable List of values.
getValue
(Object
The entry key.
name
,
int
Index of element to get.
i
)

Get a value from a multiple value.

public List<E>

Returns:

Unmodifieable List of values.
getValues
(Object
The entry key.
name
)

Get multiple values.

public Object

Returns:

The previous value or null.
put
(Object
The entry key.
name
,
Object
The entry value.
value
)

Overrides java.util.HashMap.put.

Implements java.util.Map.put.

Put and entry into the map.
public void
putAll(Map<K, V>
Map
m
)

Overrides java.util.HashMap.putAll.

Implements java.util.Map.putAll.

Put all contents of map.
public Object

Returns:

The previous value or null.
putValues
(Object
The entry key.
name
,
List<E>
The List of multiple values.
values
)

Put multi valued entry.

public Object

Returns:

The previous value or null.
putValues
(Object
The entry key.
name
,
String[]
The String array of multiple values.
values
)

Put multi valued entry.

public boolean

Returns:

true if it was removed.
removeValue
(Object
The entry key.
name
,
Object
The entry value.
value
)

Remove value.

public Map<K, V>

Returns:

Map of String arrays
toStringArrayMap
()

Inherited from java.util.HashMap:
clearcomputecomputeIfAbsentcomputeIfPresentcontainsKeycontainsValueentrySetforEachgetOrDefaultisEmptykeySetmergenewHashMapputIfAbsentremoveremovereplacereplacereplaceAllsizevalues

Constructor Detail

MultiMapback to summary
public MultiMap()

Constructor.

MultiMapback to summary
public MultiMap(int size)

Constructor.

Parameters
size:int

Capacity of the map

MultiMapback to summary
public MultiMap(Map<K, V> map)

Constructor.

Method Detail

addback to summary
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:Object

The entry key.

value:Object

The entry value.

addValuesback to summary
public void addValues(Object name, List<E> 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:Object

The entry key.

values:List<E>

The List of multiple values.

addValuesback to summary
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:Object

The entry key.

values:String[]

The String array of multiple values.

cloneback to summary
public Object clone()

Overrides java.util.HashMap.clone.

Doc from java.util.HashMap.clone.

Returns a shallow copy of this HashMap instance: the keys and values themselves are not cloned.

Returns:Object

a shallow copy of this map

getback to summary
public Object get(Object name)

Overrides java.util.HashMap.get.

Implements java.util.Map.get.

Doc from java.util.HashMap.get.

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

More formally, if this map contains a mapping from a key k to a value v such that (key==null ? k==null : key.equals(k)), then this method returns v; otherwise it returns null. (There can be at most one such mapping.)

A return value of null does not necessarily indicate that the map contains no mapping for the key; it's also possible that the map explicitly maps the key to null. The containsKey operation may be used to distinguish these two cases.

Parameters
name:Object

Doc from java.util.Map.get.

the key whose associated value is to be returned

Returns:Object

Doc from java.util.Map.get.

the value to which the specified key is mapped, or null if this map contains no mapping for the key

getStringback to summary
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:Object

The entry key.

Returns:String

String value.

getValueback to summary
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:Object

The entry key.

i:int

Index of element to get.

Returns:Object

Unmodifieable List of values.

getValuesback to summary
public List<E> getValues(Object name)

Get multiple values. Single valued entries are converted to singleton lists.

Parameters
name:Object

The entry key.

Returns:List<E>

Unmodifieable List of values.

putback to summary
public Object put(Object name, Object value)

Overrides java.util.HashMap.put.

Implements java.util.Map.put.

Put and entry into the map.

Parameters
name:Object

The entry key.

value:Object

The entry value.

Returns:Object

The previous value or null.

putAllback to summary
public void putAll(Map<K, V> m)

Overrides java.util.HashMap.putAll.

Implements java.util.Map.putAll.

Put all contents of map.

Parameters
m:Map<K, V>

Map

putValuesback to summary
public Object putValues(Object name, List<E> values)

Put multi valued entry.

Parameters
name:Object

The entry key.

values:List<E>

The List of multiple values.

Returns:Object

The previous value or null.

putValuesback to summary
public Object putValues(Object name, String[] values)

Put multi valued entry.

Parameters
name:Object

The entry key.

values:String[]

The String array of multiple values.

Returns:Object

The previous value or null.

removeValueback to summary
public boolean removeValue(Object name, Object value)

Remove value.

Parameters
name:Object

The entry key.

value:Object

The entry value.

Returns:boolean

true if it was removed.

toStringArrayMapback to summary
public Map<K, V> toStringArrayMap()
Returns:Map<K, V>

Map of String arrays