Package org.apache.commons.chain.web
Class ParameterMap<P,T>
java.lang.Object
org.apache.commons.chain.web.ParameterMap<P,T>
- Type Parameters:
P
- the type of the parameter-providerT
- the type of results supplied by this parameters
- Direct Known Subclasses:
CookieMap
,CookieMap
,MutableParameterMap
,ParamValuesMap
Implementation of
Map
for immutable parameters with a
parameter-provider.- Since:
- Chain 1.3
- Author:
- Graff Stefan
-
Nested Class Summary
-
Constructor Summary
ConstructorDescriptionParameterMap
(P parameter, Function<String, T> valueFunction, Supplier<Enumeration<String>> namesSupplier) The constructor for an immutable parameter-map. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Removes all of the mappings from this parameter-map.boolean
containsKey
(Object key) Returnstrue
if this parameter-map contains a mapping for the specified key.boolean
containsValue
(Object value) Returnstrue
if this parameter-map maps one or more keys to the specified value.entrySet()
Returns aSet
view of the mappings contained in this parameter-map.entrySet
(boolean modifiable) Returns aSet
view of the mappings contained in this map.boolean
Compares the specified object with this parameter-map for equality.Returns the value to which the specified key is mapped, ornull
if this parameter-map contains no mapping for the key.protected Supplier
<Enumeration<String>> Returns the Supplier to return anEnumeration
ofString
objects containing the names of the parameters contained in this object.protected P
Returns the parameter-class.Returns the Function to return the value of a parameter as anString
, ornull
if no parameter of the given name exists.int
hashCode()
Returns the hash code value for this parameter-map.boolean
isEmpty()
Returnstrue
if this parameter-map contains no key-value mappings.protected static String
Converts thekey
to aString
.keySet()
Returns aSet
view of the keys contained in this parameter-map.Associates the specified value with the specified key in this parameter-map.void
Copies all of the mappings from the specified map to this parameter-map.Removes the mapping for the specified key from this parameter-map if present.int
size()
Returns the number of key-value mappings in this parameter-map.toString()
Returns a string representation of this parameter-map.values()
Returns aCollection
view of the values contained in this parameter-map.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
ParameterMap
public ParameterMap(P parameter, Function<String, T> valueFunction, Supplier<Enumeration<String>> namesSupplier) The constructor for an immutable parameter-map.- Parameters:
parameter
- the parameter-providervalueFunction
- Function to return the value of a parameternamesSupplier
- Supplier to return all names of the parameter
-
-
Method Details
-
clear
Removes all of the mappings from this parameter-map. The parameter-map will be empty after this call returns.- Specified by:
clear
in interfaceMap<P,
T> - Throws:
UnsupportedOperationException
- because it is an immutable parameter-map
-
containsKey
Returnstrue
if this parameter-map contains a mapping for the specified key.- Specified by:
containsKey
in interfaceMap<P,
T> - Parameters:
key
- The key whose presence in this parameter-map is to be tested- Returns:
true
if this parameter-map contains a mapping for the specified key.
-
containsValue
Returnstrue
if this parameter-map maps one or more keys to the specified value.- Specified by:
containsValue
in interfaceMap<P,
T> - Parameters:
value
- value whose presence in this parameter-map is to be tested- Returns:
true
if this parameter-map maps one or more keys to the specified value
-
entrySet
Returns aSet
view of the mappings contained in this parameter-map. The set is not backed by the parameter-map, so changes to the parameter-map are not reflected in the set, and vice-versa. -
get
Returns the value to which the specified key is mapped, ornull
if this parameter-map contains no mapping for the key.A return value of
null
does not necessarily indicate that the parameter-map contains no mapping for the key; it's also possible that the parameter-map explicitly maps the key tonull
. ThecontainsKey
operation may be used to distinguish these two cases. -
isEmpty
Returnstrue
if this parameter-map contains no key-value mappings. -
keySet
Returns aSet
view of the keys contained in this parameter-map. The set is not backed by the parameter-map, so changes to the parameter-map are not reflected in the set, and vice-versa. -
put
Associates the specified value with the specified key in this parameter-map. If the parameter-map previously contained a mapping for the key, the old value is replaced.- Specified by:
put
in interfaceMap<P,
T> - Parameters:
key
- key with which the specified value is to be associatedvalue
- value to be associated with the specified key- Returns:
- the previous value associated with
key
, ornull
if there was no mapping forkey
. (Anull
return can also indicate that the parameter-map previously associatednull
withkey
.) - Throws:
UnsupportedOperationException
- because it is an immutable parameter-map
-
putAll
Copies all of the mappings from the specified map to this parameter-map. These mappings will replace any mappings that this parameter-map had for any of the keys currently in the specified map.- Specified by:
putAll
in interfaceMap<P,
T> - Parameters:
map
- mappings to be stored in this parameter-map- Throws:
NullPointerException
- if the specified map is nullUnsupportedOperationException
- because it is an immutable parameter-map
-
remove
Removes the mapping for the specified key from this parameter-map if present.- Specified by:
remove
in interfaceMap<P,
T> - Parameters:
key
- key whose mapping is to be removed from the parameter-map- Returns:
- the previous value associated with
key
, ornull
if there was no mapping forkey
. (Anull
return can also indicate that the parameter-map previously associatednull
withkey
.) - Throws:
UnsupportedOperationException
- because it is an immutable parameter-map
-
size
Returns the number of key-value mappings in this parameter-map. -
values
Returns aCollection
view of the values contained in this parameter-map. The collection is not backed by the parameter-map, so changes to the parameter-map are not reflected in the collection, and vice-versa. -
hashCode
Returns the hash code value for this parameter-map. The hash code of a parameter-map is defined to be the sum of the hash codes of each entry in the parameter-map'sentrySet()
view. This ensures thatm1.equals(m2)
implies thatm1.hashCode()==m2.hashCode()
for any two parameter-mapsm1
andm2
, as required by the general contract ofObject.hashCode()
. -
equals
Compares the specified object with this parameter-map for equality. Returnstrue
if the given object is also a parameter-map and the two parameter-maps represent the same mappings. More formally, two parameter-mapsm1
andm2
represent the same mappings ifm1.entrySet().equals(m2.entrySet())
.- Specified by:
equals
in interfaceMap<P,
T> - Overrides:
equals
in classObject
- Parameters:
obj
- object to be compared for equality with this parameter-map- Returns:
true
if the specified object is equal to this parameter-map- Implementation Requirements:
- This implementation first checks if the specified object is this
parameter-map; if so it returns
true
. Then, it checks if the specified object is the identical class this parameter-map; if not, it returnsfalse
. If so, it calls theequals()
from the parameter-provider and returns its return-code.
-
toString
Returns a string representation of this parameter-map. The string representation consists of a list of key-value mappings in the order returned by the parameter-map'sentrySet
view's iterator, enclosed in braces ("{}"
). Adjacent mappings are separated by the characters", "
(comma and space). Each key-value mapping is rendered as the key followed by an equals sign ("="
) followed by the associated value. Keys and values are converted to strings as byString.valueOf(Object)
. -
getParameter
Returns the parameter-class.- Returns:
- the parameter-class
-
getValueFunction
Returns the Function to return the value of a parameter as anString
, ornull
if no parameter of the given name exists.- Returns:
- the Function to return the value
-
getNamesSupplier
Returns the Supplier to return anEnumeration
ofString
objects containing the names of the parameters contained in this object.- Returns:
- Supplier to return an
Enumeration
with all names of the parameters
-
entrySet
Returns aSet
view of the mappings contained in this map.- Parameters:
modifiable
- Whether the entries should allow modification or not- Returns:
- a set view of the mappings contained in this map
-
key
Converts thekey
to aString
.- Parameters:
key
- the key- Returns:
- the key as
String
-