org.mortbay.util

Class MultiMap

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(int size)
Constructor.
MultiMap(Map map)
Constructor.
Method Summary
voidadd(Object name, Object value)
Add value to multi valued entry.
voidaddValues(Object name, List values)
Add values to multi valued entry.
voidaddValues(Object name, String[] values)
Add values to multi valued entry.
Objectclone()
Objectget(Object name)
StringgetString(Object name)
Get value as String.
ObjectgetValue(Object name, int i)
Get a value from a multiple value.
ListgetValues(Object name)
Get multiple values.
Objectput(Object name, Object value)
Put and entry into the map.
voidputAll(Map m)
Put all contents of map.
ObjectputValues(Object name, List values)
Put multi valued entry.
ObjectputValues(Object name, String[] values)
Put multi valued entry.
booleanremoveValue(Object name, Object value)
Remove value.
MaptoStringArrayMap()

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

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.