Package jodd.http
Class HttpMultiMap<V>
- java.lang.Object
-
- jodd.http.HttpMultiMap<V>
-
- All Implemented Interfaces:
java.lang.Iterable<java.util.Map.Entry<java.lang.String,V>>
- Direct Known Subclasses:
HeadersMultiMap
public class HttpMultiMap<V> extends java.lang.Object implements java.lang.Iterable<java.util.Map.Entry<java.lang.String,V>>General purpose HTTP multi-map. It's optimized Linked-HashMap, designed for small number of items andStringnon-null keys. It stores keys in case-sensitive way, but, by default, you can read them in case-insensitive way.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classHttpMultiMap.MapEntry<V>
-
Field Summary
Fields Modifier and Type Field Description private static intBUCKET_SIZEprivate booleancaseSensitiveprivate HttpMultiMap.MapEntry<V>[]entriesprivate HttpMultiMap.MapEntry<V>head
-
Constructor Summary
Constructors Modifier Constructor Description protectedHttpMultiMap(boolean caseSensitive)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void_add(int hash, int index, java.lang.String name, V value)private void_remove(int hash, int index, java.lang.String name)private HttpMultiMap<V>_set(java.lang.Iterable<java.util.Map.Entry<java.lang.String,V>> map)HttpMultiMap<V>add(java.lang.String name, V value)HttpMultiMap<V>addAll(java.lang.String name, java.lang.Iterable<V> values)HttpMultiMap<V>addAll(java.util.Map<java.lang.String,V> map)HttpMultiMap<V>addAll(HttpMultiMap<V> map)HttpMultiMap<V>clear()Clears the map.booleancontains(java.lang.String name)Returnstrueif name exist.java.util.List<java.util.Map.Entry<java.lang.String,V>>entries()Returns all the entries of this map.private booleaneq(java.lang.String name1, java.lang.String name2)Returnstrueif two names are the same.Vget(java.lang.String name)Returns the first value from the map associated with the name.java.util.List<V>getAll(java.lang.String name)Returns all values associated with the name.java.util.Map.Entry<java.lang.String,V>getEntry(java.lang.String name)Returns first entry for given name.private inthash(java.lang.String name)Calculates hash value of the input string.private static intindex(int hash)Calculates bucket index from the hash.booleanisEmpty()Returnstrueif map is empty.java.util.Iterator<java.util.Map.Entry<java.lang.String,V>>iterator()Returns iterator of all entries.java.util.Set<java.lang.String>names()static <T> HttpMultiMap<T>newCaseInsensitiveMap()Creates new case-insensitive multimap.static <T> HttpMultiMap<T>newCaseSensitiveMap()Creates new case-insensitive map.HttpMultiMap<V>remove(java.lang.String name)HttpMultiMap<V>set(java.lang.String name, V value)HttpMultiMap<V>setAll(java.lang.String name, java.lang.Iterable<V> values)HttpMultiMap<V>setAll(java.util.Map<java.lang.String,V> map)HttpMultiMap<V>setAll(HttpMultiMap<V> multiMap)intsize()Returns the number of keys.java.lang.StringtoString()
-
-
-
Field Detail
-
BUCKET_SIZE
private static final int BUCKET_SIZE
- See Also:
- Constant Field Values
-
caseSensitive
private final boolean caseSensitive
-
entries
private final HttpMultiMap.MapEntry<V>[] entries
-
head
private final HttpMultiMap.MapEntry<V> head
-
-
Method Detail
-
newCaseInsensitiveMap
public static <T> HttpMultiMap<T> newCaseInsensitiveMap()
Creates new case-insensitive multimap.
-
newCaseSensitiveMap
public static <T> HttpMultiMap<T> newCaseSensitiveMap()
Creates new case-insensitive map.
-
hash
private int hash(java.lang.String name)
Calculates hash value of the input string.
-
index
private static int index(int hash)
Calculates bucket index from the hash.
-
eq
private boolean eq(java.lang.String name1, java.lang.String name2)Returnstrueif two names are the same.
-
size
public int size()
Returns the number of keys. This is not the number of all elements. Not optimized.
-
clear
public HttpMultiMap<V> clear()
Clears the map.
-
contains
public boolean contains(java.lang.String name)
Returnstrueif name exist.
-
isEmpty
public boolean isEmpty()
Returnstrueif map is empty.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
_set
private HttpMultiMap<V> _set(java.lang.Iterable<java.util.Map.Entry<java.lang.String,V>> map)
-
setAll
public HttpMultiMap<V> setAll(HttpMultiMap<V> multiMap)
-
setAll
public HttpMultiMap<V> setAll(java.util.Map<java.lang.String,V> map)
-
set
public HttpMultiMap<V> set(java.lang.String name, V value)
-
setAll
public HttpMultiMap<V> setAll(java.lang.String name, java.lang.Iterable<V> values)
-
add
public HttpMultiMap<V> add(java.lang.String name, V value)
-
addAll
public HttpMultiMap<V> addAll(java.lang.String name, java.lang.Iterable<V> values)
-
addAll
public HttpMultiMap<V> addAll(HttpMultiMap<V> map)
-
addAll
public HttpMultiMap<V> addAll(java.util.Map<java.lang.String,V> map)
-
_add
private void _add(int hash, int index, java.lang.String name, V value)
-
remove
public HttpMultiMap<V> remove(java.lang.String name)
-
_remove
private void _remove(int hash, int index, java.lang.String name)
-
get
public V get(java.lang.String name)
Returns the first value from the map associated with the name. Returnsnullif name does not exist or if associated value isnull.
-
getEntry
public java.util.Map.Entry<java.lang.String,V> getEntry(java.lang.String name)
Returns first entry for given name. Returnsnullif entry does not exist.
-
getAll
public java.util.List<V> getAll(java.lang.String name)
Returns all values associated with the name.
-
iterator
public java.util.Iterator<java.util.Map.Entry<java.lang.String,V>> iterator()
Returns iterator of all entries.- Specified by:
iteratorin interfacejava.lang.Iterable<V>
-
names
public java.util.Set<java.lang.String> names()
-
entries
public java.util.List<java.util.Map.Entry<java.lang.String,V>> entries()
Returns all the entries of this map. Case sensitivity does not influence the returned list, it always contains all of the values.
-
-