org.eclipse.jetty.util
Class MultiMap<K>

java.lang.Object
  extended by org.eclipse.jetty.util.MultiMap<K>
Type Parameters:
K - The key type of the map.
All Implemented Interfaces:
java.io.Serializable, java.util.concurrent.ConcurrentMap<K,java.lang.Object>, java.util.Map<K,java.lang.Object>
Direct Known Subclasses:
UrlEncoded

public class MultiMap<K>
extends java.lang.Object
implements java.util.concurrent.ConcurrentMap<K,java.lang.Object>, java.io.Serializable

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

Implemented as a map of LazyList values

See Also:
LazyList, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
MultiMap()
           
MultiMap(boolean concurrent)
           
MultiMap(int capacity)
           
MultiMap(java.util.Map map)
           
MultiMap(MultiMap<K> map)
           
 
Method Summary
 void add(K name, java.lang.Object value)
          Add value to multi valued entry.
 void addValues(K name, java.util.List values)
          Add values to multi valued entry.
 void addValues(K name, java.lang.String[] values)
          Add values to multi valued entry.
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set<java.util.Map.Entry<K,java.lang.Object>> entrySet()
           
 boolean equals(java.lang.Object o)
           
 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.
 int hashCode()
           
 boolean isEmpty()
           
 java.util.Set<K> keySet()
           
 java.lang.Object put(K 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 putIfAbsent(K key, java.lang.Object value)
           
 java.lang.Object putValues(K name, java.util.List values)
          Put multi valued entry.
 java.lang.Object putValues(K name, java.lang.String[] values)
          Put multi valued entry.
 java.lang.Object remove(java.lang.Object key)
           
 boolean remove(java.lang.Object key, java.lang.Object value)
           
 boolean removeValue(K name, java.lang.Object value)
          Remove value.
 java.lang.Object replace(K key, java.lang.Object value)
           
 boolean replace(K key, java.lang.Object oldValue, java.lang.Object newValue)
           
 int size()
           
 java.lang.String toString()
           
 java.util.Map toStringArrayMap()
           
 java.util.Collection<java.lang.Object> values()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MultiMap

public MultiMap()

MultiMap

public MultiMap(java.util.Map map)

MultiMap

public MultiMap(MultiMap<K> map)

MultiMap

public MultiMap(int capacity)

MultiMap

public MultiMap(boolean concurrent)
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<K,java.lang.Object>

put

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

Specified by:
put in interface java.util.Map<K,java.lang.Object>
Parameters:
name - The entry key.
value - The entry value.
Returns:
The previous value or null.

putValues

public java.lang.Object putValues(K 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(K 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(K 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(K 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(K 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(K 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<K,java.lang.Object>
Parameters:
m - Map

toStringArrayMap

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

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

clear

public void clear()
Specified by:
clear in interface java.util.Map<K,java.lang.Object>

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map<K,java.lang.Object>

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<K,java.lang.Object>

entrySet

public java.util.Set<java.util.Map.Entry<K,java.lang.Object>> entrySet()
Specified by:
entrySet in interface java.util.Map<K,java.lang.Object>

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Map<K,java.lang.Object>
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Specified by:
hashCode in interface java.util.Map<K,java.lang.Object>
Overrides:
hashCode in class java.lang.Object

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<K,java.lang.Object>

keySet

public java.util.Set<K> keySet()
Specified by:
keySet in interface java.util.Map<K,java.lang.Object>

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map<K,java.lang.Object>

size

public int size()
Specified by:
size in interface java.util.Map<K,java.lang.Object>

values

public java.util.Collection<java.lang.Object> values()
Specified by:
values in interface java.util.Map<K,java.lang.Object>

putIfAbsent

public java.lang.Object putIfAbsent(K key,
                                    java.lang.Object value)
Specified by:
putIfAbsent in interface java.util.concurrent.ConcurrentMap<K,java.lang.Object>

remove

public boolean remove(java.lang.Object key,
                      java.lang.Object value)
Specified by:
remove in interface java.util.concurrent.ConcurrentMap<K,java.lang.Object>

replace

public boolean replace(K key,
                       java.lang.Object oldValue,
                       java.lang.Object newValue)
Specified by:
replace in interface java.util.concurrent.ConcurrentMap<K,java.lang.Object>

replace

public java.lang.Object replace(K key,
                                java.lang.Object value)
Specified by:
replace in interface java.util.concurrent.ConcurrentMap<K,java.lang.Object>


Copyright © 1995-2010 Mort Bay Consulting. All Rights Reserved.