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:
MutableParameterMap,ParamValuesMap
Implementation of
Map for immutable parameters with a
parameter-provider.- Since:
- Chain 1.3
- Author:
- Graff Stefan
-
Nested Class Summary
-
Constructor Summary
ConstructorsConstructorDescriptionParameterMap(P parameter, Function<String, T> valueFunction, Supplier<Enumeration<String>> namesSupplier) The constructor for an immutable parameter-map. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Removes all of the mappings from this parameter-map.booleancontainsKey(Object key) Returnstrueif this parameter-map contains a mapping for the specified key.booleancontainsValue(Object value) Returnstrueif this parameter-map maps one or more keys to the specified value.entrySet()Returns aSetview of the mappings contained in this parameter-map.entrySet(boolean modifiable) Returns aSetview of the mappings contained in this map.booleanCompares the specified object with this parameter-map for equality.Returns the value to which the specified key is mapped, ornullif this parameter-map contains no mapping for the key.protected Supplier<Enumeration<String>> Returns the Supplier to return anEnumerationofStringobjects containing the names of the parameters contained in this object.protected PReturns the parameter-class.Returns the Function to return the value of a parameter as anString, ornullif no parameter of the given name exists.inthashCode()Returns the hash code value for this parameter-map.booleanisEmpty()Returnstrueif this parameter-map contains no key-value mappings.protected static StringConverts thekeyto aString.keySet()Returns aSetview of the keys contained in this parameter-map.Associates the specified value with the specified key in this parameter-map.voidCopies 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.intsize()Returns the number of key-value mappings in this parameter-map.toString()Returns a string representation of this parameter-map.values()Returns aCollectionview of the values contained in this parameter-map.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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:
clearin interfaceMap<P,T> - Throws:
UnsupportedOperationException- because it is an immutable parameter-map
-
containsKey
Returnstrueif this parameter-map contains a mapping for the specified key.- Specified by:
containsKeyin interfaceMap<P,T> - Parameters:
key- The key whose presence in this parameter-map is to be tested- Returns:
trueif this parameter-map contains a mapping for the specified key.
-
containsValue
Returnstrueif this parameter-map maps one or more keys to the specified value.- Specified by:
containsValuein interfaceMap<P,T> - Parameters:
value- value whose presence in this parameter-map is to be tested- Returns:
trueif this parameter-map maps one or more keys to the specified value
-
entrySet
Returns aSetview 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, ornullif this parameter-map contains no mapping for the key.A return value of
nulldoes 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. ThecontainsKeyoperation may be used to distinguish these two cases. -
isEmpty
Returnstrueif this parameter-map contains no key-value mappings. -
keySet
Returns aSetview 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:
putin 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, ornullif there was no mapping forkey. (Anullreturn can also indicate that the parameter-map previously associatednullwithkey.) - 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:
putAllin 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:
removein interfaceMap<P,T> - Parameters:
key- key whose mapping is to be removed from the parameter-map- Returns:
- the previous value associated with
key, ornullif there was no mapping forkey. (Anullreturn can also indicate that the parameter-map previously associatednullwithkey.) - Throws:
UnsupportedOperationException- because it is an immutable parameter-map
-
size
Returns the number of key-value mappings in this parameter-map. -
values
Returns aCollectionview 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-mapsm1andm2, as required by the general contract ofObject.hashCode(). -
equals
Compares the specified object with this parameter-map for equality. Returnstrueif the given object is also a parameter-map and the two parameter-maps represent the same mappings. More formally, two parameter-mapsm1andm2represent the same mappings ifm1.entrySet().equals(m2.entrySet()).- Specified by:
equalsin interfaceMap<P,T> - Overrides:
equalsin classObject- Parameters:
obj- object to be compared for equality with this parameter-map- Returns:
trueif 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'sentrySetview'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, ornullif no parameter of the given name exists.- Returns:
- the Function to return the value
-
getNamesSupplier
Returns the Supplier to return anEnumerationofStringobjects containing the names of the parameters contained in this object.- Returns:
- Supplier to return an
Enumerationwith all names of the parameters
-
entrySet
Returns aSetview 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 thekeyto aString.- Parameters:
key- the key- Returns:
- the key as
String
-