|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.abstracthorizon.danube.http.util.MultiStringHashMap
public class MultiStringHashMap
MultiStringMap
implementation using HashMap
This implementation uses map and is storing multiple elements in a list.
If only one element remains in the list
then it is replaced with that element only.
Nested Class Summary | |
---|---|
protected class |
MultiStringHashMap.InternalMapEntry<K,V>
Map entry for internal use |
Field Summary | |
---|---|
protected Map<String,Object> |
map
Backing storage. |
Constructor Summary | |
---|---|
MultiStringHashMap()
Constructor. |
|
MultiStringHashMap(int initialCapacity)
Constructor. |
|
MultiStringHashMap(int initialCapacity,
float loadFactor)
Constructor. |
Method Summary | |
---|---|
void |
add(String id,
String value)
Adds new element to the map. |
void |
addAll(String id,
Collection<String> values)
Adds all elements from the given collection |
void |
addAll(String id,
String[] values)
Adds all elements from the given array. |
void |
clear()
Clears the map |
boolean |
containsKey(String id)
Returns true if there is at least one entry |
Collection<Map.Entry<String,String>> |
getAllEntries()
Returns list of all entries. |
String[] |
getAsArray(String id)
Returns array of all elements under asked key. |
List<String> |
getAsList(String id)
Returns list of all elements under asked key. |
Map<String,Object> |
getAsMap()
Returns a map that contains all elements. |
int |
getEntrySize(String id)
Returns number of entries for given key |
String |
getFirst(String id)
Retrieves element from the given key. |
String |
getOnly(String id)
Retrieves element from the given key. |
Set<String> |
keySet()
Returns key set |
void |
putAll(String id,
Collection<String> values)
Replaces existing element(s), if there are any under the given key, with the given values. |
void |
putAll(String id,
String[] values)
Replaces existing element(s), if there are any under the given key, with the given values. |
void |
putOnly(String id,
String value)
Replaces existing element(s), if there are any under the given key, with the given value. |
String |
remove(String id,
int index)
Removes n-th element from the given key. |
Collection<String> |
removeAll(String id)
Removes all elements from the given key |
String |
removeFirst(String id)
Removes first element from the given key. |
int |
size()
Number of keys in the map. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected Map<String,Object> map
Constructor Detail |
---|
public MultiStringHashMap()
public MultiStringHashMap(int initialCapacity)
initialCapacity
- initial capacity of a backing mappublic MultiStringHashMap(int initialCapacity, float loadFactor)
initialCapacity
- initial capacity of a backing maploadFactor
- load factory of a backing mapMethod Detail |
---|
public void add(String id, String value)
Adds new element to the map. If no entries with given id exist than this is going to be the first. If there are already values under given id then this is going to be added as a new one.
This implementation if there is already one value in the backing map converts it to a list and adds both (old and new values) to it.
add
in interface MultiStringMap
id
- keyvalue
- value to be added
IllegalStateException
- if existing element of the backing storage is not a string or a listpublic void addAll(String id, String[] values)
Adds all elements from the given array.
This implementation is using addAll(String, Collection)
to add values
addAll
in interface MultiStringMap
id
- keyvalues
- array of valuesMultiStringMap.add(String, String)
public void addAll(String id, Collection<String> values)
Adds all elements from the given collection
This implementation if there is already one value in the backing map converts it to a list and adds both (old and new values) to it.
addAll
in interface MultiStringMap
id
- keyvalues
- collection which elements are to be added
IllegalStateException
- if existing element of the backing storage is not a string or a listMultiStringMap.add(String, String)
public void putOnly(String id, String value)
putOnly
in interface MultiStringMap
id
- keyvalue
- value to be put to the mappublic void putAll(String id, String[] values)
Replaces existing element(s), if there are any under the given key, with the given values.
If array's length is greater then one it stores given array of strings as a list, if arrayls. If array's length is exactly one then value of it is stored as a string while if array's length is zero then it is removed from the backing storage.
putAll
in interface MultiStringMap
id
- keyvalues
- values to be put to the mapMultiStringMap.putOnly(String, String)
public void putAll(String id, Collection<String> values)
Replaces existing element(s), if there are any under the given key, with the given values.
If array's length is greater then one it stores given array of strings as a list, if arrayls. If array's length is exactly one then value of it is stored as a string while if array's length is zero then it is removed from the backing storage.
Note: This implementation is not ensuring that all collection elements are of String
type.
putAll
in interface MultiStringMap
id
- keyvalues
- collection of values to be put to the mapMultiStringMap.putOnly(String, String)
public Collection<String> removeAll(String id)
removeAll
in interface MultiStringMap
id
- keypublic String removeFirst(String id)
Removes first element from the given key. If there was only one element then there will be no more elements under the given key
Implementation ensures that if list is reduced to only one element then that element is stored instead of the list itself.
removeFirst
in interface MultiStringMap
id
- key
IllegalStateException
- if the element of the backing storage is not string nor list or there are no elements to be removedpublic String remove(String id, int index)
Removes n-th element from the given key.
Implementation ensures that if list is reduced to only one element then that element is stored instead of the list itself.
remove
in interface MultiStringMap
id
- keyindex
- index of the element to be removed
IndexOutOfBoundsException
- if there are no elements under the given key
IllegalStateException
- if the element of the backing storage is not string nor list or there are no elements to be removedpublic boolean containsKey(String id)
true
if there is at least one entry
containsKey
in interface MultiStringMap
id
- key
true
if there is at least one entrypublic int getEntrySize(String id)
getEntrySize
in interface MultiStringMap
id
- key
public String getOnly(String id)
getOnly
in interface MultiStringMap
id
- key of the asked element
IllegalStateException
- if there are more then one element under this key or nor string or list is stored in the backing storagepublic String getFirst(String id)
getFirst
in interface MultiStringMap
id
- key of the asked element
IllegalStateException
- if there are more then one element under this key or nor string or list is stored in the backing storagepublic String[] getAsArray(String id)
getAsArray
in interface MultiStringMap
id
- key of the asked elements
IllegalStateException
- if the element of the backing storage is not string nor list or there are no elements to be removedpublic List<String> getAsList(String id)
getAsList
in interface MultiStringMap
id
- key of the asked elements
IllegalStateException
- if the element of the backing storage is not string nor list or there are no elements to be removedpublic void clear()
clear
in interface MultiStringMap
public Set<String> keySet()
keySet
in interface MultiStringMap
public Map<String,Object> getAsMap()
getAsMap
in interface MultiStringMap
public Collection<Map.Entry<String,String>> getAllEntries()
getAllEntries
in interface MultiStringMap
IllegalStateException
- if the element of the backing storage is not string nor list or there are no elements to be removedpublic int size()
size
in interface MultiStringMap
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |