Class ValueMap
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<K,V>
-
- java.util.LinkedHashMap<java.lang.String,java.lang.Object>
-
- org.apache.wicket.util.value.ValueMap
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable,java.util.Map<java.lang.String,java.lang.Object>,IValueMap
- Direct Known Subclasses:
AttributeMap
public class ValueMap extends java.util.LinkedHashMap<java.lang.String,java.lang.Object> implements IValueMap
AIValueMapimplementation that holds values, parsesStrings, and exposes a variety of convenience methods.In addition to a no-arg constructor and a copy constructor that takes a
Mapargument,ValueMaps can be constructed using a parsing constructor.ValueMap(String)will parse values from the string in comma separated key/value assignment pairs. For example,new ValueMap("a=9,b=foo").Values can be retrieved from the
ValueMapin the usual way or with methods that do handy conversions to various types, includingString,StringValue,int,long,double,TimeandDuration.The
makeImmutablemethod will make the underlyingMapimmutable. Further attempts to change theMapwill result in aRuntimeException.The
toStringmethod converts aValueMapobject to a readable key/value string for diagnostics.- Since:
- 1.2.6
- Author:
- Jonathan Locke, Doug Donohoe
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description ValueMap()Constructs emptyValueMap.ValueMap(java.lang.String keyValuePairs)Constructor.ValueMap(java.lang.String keyValuePairs, java.lang.String delimiter)Constructor.ValueMap(java.lang.String keyValuePairs, java.lang.String delimiter, MetaPattern valuePattern)Constructor.ValueMap(java.util.Map<? extends java.lang.String,?> map)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectadd(java.lang.String key, java.lang.String value)Adds the value to thisValueMapwith the given key.voidclear()java.lang.BooleangetAsBoolean(java.lang.String key)Retrieves aBooleanvalue by key.booleangetAsBoolean(java.lang.String key, boolean defaultValue)Retrieves abooleanvalue by key.java.lang.DoublegetAsDouble(java.lang.String key)Retrieves aDoublevalue by key.doublegetAsDouble(java.lang.String key, double defaultValue)Retrieves adoublevalue by key.DurationgetAsDuration(java.lang.String key)Retrieves aDurationvalue by key.DurationgetAsDuration(java.lang.String key, Duration defaultValue)Retrieves aDurationvalue by key.<T extends java.lang.Enum<T>>
TgetAsEnum(java.lang.String key, java.lang.Class<T> eClass)Retrieves anEnumvalue by key.<T extends java.lang.Enum<T>>
TgetAsEnum(java.lang.String key, java.lang.Class<T> eClass, T defaultValue)Retrieves anEnumvalue by key.<T extends java.lang.Enum<T>>
TgetAsEnum(java.lang.String key, T defaultValue)Retrieves anEnumvalue by key.java.lang.IntegergetAsInteger(java.lang.String key)Retrieves anIntegervalue by key.intgetAsInteger(java.lang.String key, int defaultValue)Retrieves anintegervalue by key.java.lang.LonggetAsLong(java.lang.String key)Retrieves aLongvalue by key.longgetAsLong(java.lang.String key, long defaultValue)Retrieves alongvalue by key.TimegetAsTime(java.lang.String key)Retrieves aTimevalue by key.TimegetAsTime(java.lang.String key, Time defaultValue)Retrieves aTimevalue by key.booleangetBoolean(java.lang.String key)Retrieves abooleanvalue by key.java.lang.CharSequencegetCharSequence(java.lang.String key)Retrieves aCharSequenceby key.doublegetDouble(java.lang.String key)Retrieves adoublevalue by key.doublegetDouble(java.lang.String key, double defaultValue)Retrieves adoublevalue by key, using a default value if not found.DurationgetDuration(java.lang.String key)Retrieves aDurationby key.intgetInt(java.lang.String key)Retrieves anintvalue by key.intgetInt(java.lang.String key, int defaultValue)Retrieves anintvalue by key, using a default value if not found.java.lang.StringgetKey(java.lang.String key)Provided that the hash key is aStringand you need to access the value ignoring the key's case (upper- or lowercase letters), then you may use this method to get the correct writing.longgetLong(java.lang.String key)Retrieves alongvalue by key.longgetLong(java.lang.String key, long defaultValue)Retrieves alongvalue by key, using a default value if not found.java.lang.StringgetString(java.lang.String key)Retrieves aStringby key.java.lang.StringgetString(java.lang.String key, java.lang.String defaultValue)Retrieves aStringby key, using a default value if not found.java.lang.String[]getStringArray(java.lang.String key)Retrieves aStringarray by key.StringValuegetStringValue(java.lang.String key)Retrieves aStringValueobject by key.TimegetTime(java.lang.String key)Retrieves aTimeobject by key.booleanisImmutable()Returns whether or not thisIValueMapis immutable.IValueMapmakeImmutable()Makes thisIValueMapimmutable by changing the underlying map representation to aCollections.unmodifiableMap.java.lang.Objectput(java.lang.String key, java.lang.Object value)voidputAll(java.util.Map<? extends java.lang.String,?> map)java.lang.Objectremove(java.lang.Object key)java.lang.StringtoString()Generates aStringrepresentation of this object.-
Methods inherited from class java.util.LinkedHashMap
containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, values
-
Methods inherited from class java.util.HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, putIfAbsent, remove, replace, replace, size
-
-
-
-
Field Detail
-
EMPTY_MAP
public static final ValueMap EMPTY_MAP
an emptyValueMap.
-
-
Constructor Detail
-
ValueMap
public ValueMap()
Constructs emptyValueMap.
-
ValueMap
public ValueMap(java.util.Map<? extends java.lang.String,?> map)
Copy constructor.- Parameters:
map- theValueMapto copy
-
ValueMap
public ValueMap(java.lang.String keyValuePairs)
Constructor.NOTE: Please use
RequestUtils.decodeParameters()if you wish to properly decode a request URL.- Parameters:
keyValuePairs- list of key/value pairs separated by commas. For example, "param1=foo,param2=bar"
-
ValueMap
public ValueMap(java.lang.String keyValuePairs, java.lang.String delimiter)Constructor.NOTE: Please use
RequestUtils.decodeParameters()if you wish to properly decode a request URL.- Parameters:
keyValuePairs- list of key/value pairs separated by a given delimiter. For example, "param1=foo,param2=bar" where delimiter is ",".delimiter- delimiterStringused to separate key/value pairs
-
ValueMap
public ValueMap(java.lang.String keyValuePairs, java.lang.String delimiter, MetaPattern valuePattern)Constructor.- Parameters:
keyValuePairs- list of key/value pairs separated by a given delimiter. For example, "param1=foo,param2=bar" where delimiter is ",".delimiter- delimiter string used to separate key/value pairsvaluePattern- pattern for value. To pass a simple regular expression, pass "new MetaPattern(regexp)".
-
-
Method Detail
-
clear
public final void clear()
- Specified by:
clearin interfacejava.util.Map<java.lang.String,java.lang.Object>- Overrides:
clearin classjava.util.LinkedHashMap<java.lang.String,java.lang.Object>- See Also:
Map.clear()
-
getBoolean
public final boolean getBoolean(java.lang.String key) throws StringValueConversionExceptionDescription copied from interface:IValueMapRetrieves abooleanvalue by key.- Specified by:
getBooleanin interfaceIValueMap- Parameters:
key- the key- Returns:
- the value
- Throws:
StringValueConversionException- See Also:
IValueMap.getBoolean(String)
-
getDouble
public final double getDouble(java.lang.String key) throws StringValueConversionExceptionDescription copied from interface:IValueMapRetrieves adoublevalue by key.- Specified by:
getDoublein interfaceIValueMap- Parameters:
key- the key- Returns:
- the value
- Throws:
StringValueConversionException- See Also:
IValueMap.getDouble(String)
-
getDouble
public final double getDouble(java.lang.String key, double defaultValue)Description copied from interface:IValueMapRetrieves adoublevalue by key, using a default value if not found.- Specified by:
getDoublein interfaceIValueMap- Parameters:
key- the keydefaultValue- value to use if no value is in thisIValueMap- Returns:
- the value
- See Also:
IValueMap.getDouble(String, double)
-
getDuration
public final Duration getDuration(java.lang.String key) throws StringValueConversionException
Description copied from interface:IValueMapRetrieves aDurationby key.- Specified by:
getDurationin interfaceIValueMap- Parameters:
key- the key- Returns:
- the
Durationvalue - Throws:
StringValueConversionException- See Also:
IValueMap.getDuration(String)
-
getInt
public final int getInt(java.lang.String key) throws StringValueConversionExceptionDescription copied from interface:IValueMapRetrieves anintvalue by key.- Specified by:
getIntin interfaceIValueMap- Parameters:
key- the key- Returns:
- the value
- Throws:
StringValueConversionException- See Also:
IValueMap.getInt(String)
-
getInt
public final int getInt(java.lang.String key, int defaultValue)Description copied from interface:IValueMapRetrieves anintvalue by key, using a default value if not found.- Specified by:
getIntin interfaceIValueMap- Parameters:
key- the keydefaultValue- value to use if no value is in thisIValueMap- Returns:
- the value
- See Also:
IValueMap.getInt(String, int)
-
getLong
public final long getLong(java.lang.String key) throws StringValueConversionExceptionDescription copied from interface:IValueMapRetrieves alongvalue by key.- Specified by:
getLongin interfaceIValueMap- Parameters:
key- the key- Returns:
- the value
- Throws:
StringValueConversionException- See Also:
IValueMap.getLong(String)
-
getLong
public final long getLong(java.lang.String key, long defaultValue)Description copied from interface:IValueMapRetrieves alongvalue by key, using a default value if not found.- Specified by:
getLongin interfaceIValueMap- Parameters:
key- the keydefaultValue- value to use if no value in thisIValueMap- Returns:
- the value
- See Also:
IValueMap.getLong(String, long)
-
getString
public final java.lang.String getString(java.lang.String key, java.lang.String defaultValue)Description copied from interface:IValueMapRetrieves aStringby key, using a default value if not found.- Specified by:
getStringin interfaceIValueMap- Parameters:
key- the keydefaultValue- default value to return if value isnull- Returns:
- the
String - See Also:
IValueMap.getString(String, String)
-
getString
public final java.lang.String getString(java.lang.String key)
Description copied from interface:IValueMapRetrieves aStringby key.- Specified by:
getStringin interfaceIValueMap- Parameters:
key- the key- Returns:
- the
String - See Also:
IValueMap.getString(String)
-
getCharSequence
public final java.lang.CharSequence getCharSequence(java.lang.String key)
Description copied from interface:IValueMapRetrieves aCharSequenceby key.- Specified by:
getCharSequencein interfaceIValueMap- Parameters:
key- the key- Returns:
- the
CharSequence - See Also:
IValueMap.getCharSequence(String)
-
getStringArray
public java.lang.String[] getStringArray(java.lang.String key)
Description copied from interface:IValueMapRetrieves aStringarray by key. If the value was aString[]it will be returned directly. If it was aStringit will be converted to aStringarray of length one. If it was an array of another type, aStringarray will be made and each element will be converted to aString.- Specified by:
getStringArrayin interfaceIValueMap- Parameters:
key- the key- Returns:
- the
Stringarray of that key - See Also:
IValueMap.getStringArray(String)
-
getStringValue
public StringValue getStringValue(java.lang.String key)
Description copied from interface:IValueMapRetrieves aStringValueobject by key.- Specified by:
getStringValuein interfaceIValueMap- Parameters:
key- the key- Returns:
- the
StringValueobject - See Also:
IValueMap.getStringValue(String)
-
getTime
public final Time getTime(java.lang.String key) throws StringValueConversionException
Description copied from interface:IValueMapRetrieves aTimeobject by key.- Specified by:
getTimein interfaceIValueMap- Parameters:
key- the key- Returns:
- the
Timeobject - Throws:
StringValueConversionException- See Also:
IValueMap.getTime(String)
-
isImmutable
public final boolean isImmutable()
Description copied from interface:IValueMapReturns whether or not thisIValueMapis immutable.- Specified by:
isImmutablein interfaceIValueMap- Returns:
- whether or not this
IValueMapis immutable - See Also:
IValueMap.isImmutable()
-
makeImmutable
public final IValueMap makeImmutable()
Description copied from interface:IValueMapMakes thisIValueMapimmutable by changing the underlying map representation to aCollections.unmodifiableMap. After calling this method, any attempt to modify thisIValueMapwill result in aRuntimeExceptionbeing thrown by theCollectionsframework.- Specified by:
makeImmutablein interfaceIValueMap- Returns:
- this
IValueMap - See Also:
IValueMap.makeImmutable()
-
put
public java.lang.Object put(java.lang.String key, java.lang.Object value)- Specified by:
putin interfacejava.util.Map<java.lang.String,java.lang.Object>- Overrides:
putin classjava.util.HashMap<java.lang.String,java.lang.Object>- See Also:
Map.put(Object, Object)
-
add
public final java.lang.Object add(java.lang.String key, java.lang.String value)Adds the value to thisValueMapwith the given key. If the key already is in theValueMapit will combine the values into aStringarray, else it will just store the value itself.- Parameters:
key- the key to store the value undervalue- the value that must be added/merged to theValueMap- Returns:
- the value itself if there was no previous value, or a
Stringarray with the combined values
-
putAll
public void putAll(java.util.Map<? extends java.lang.String,?> map)
- Specified by:
putAllin interfacejava.util.Map<java.lang.String,java.lang.Object>- Overrides:
putAllin classjava.util.HashMap<java.lang.String,java.lang.Object>- See Also:
Map.putAll(java.util.Map)
-
remove
public java.lang.Object remove(java.lang.Object key)
- Specified by:
removein interfacejava.util.Map<java.lang.String,java.lang.Object>- Overrides:
removein classjava.util.HashMap<java.lang.String,java.lang.Object>- See Also:
Map.remove(java.lang.Object)
-
getKey
public java.lang.String getKey(java.lang.String key)
Description copied from interface:IValueMapProvided that the hash key is aStringand you need to access the value ignoring the key's case (upper- or lowercase letters), then you may use this method to get the correct writing.- Specified by:
getKeyin interfaceIValueMap- Parameters:
key- the key- Returns:
- the key with the correct writing
- See Also:
IValueMap.getKey(String)
-
toString
public java.lang.String toString()
Generates aStringrepresentation of this object.- Overrides:
toStringin classjava.util.AbstractMap<java.lang.String,java.lang.Object>- Returns:
Stringrepresentation of thisValueMapconsistent with the tag-attribute style of markup elements. For example:a="x" b="y" c="z".
-
getAsBoolean
public java.lang.Boolean getAsBoolean(java.lang.String key)
Description copied from interface:IValueMapRetrieves aBooleanvalue by key.- Specified by:
getAsBooleanin interfaceIValueMap- Parameters:
key- the key- Returns:
- the value or null if value is not a valid boolean or no value is in this
IValueMap - See Also:
IValueMap.getAsBoolean(String)
-
getAsBoolean
public boolean getAsBoolean(java.lang.String key, boolean defaultValue)Description copied from interface:IValueMapRetrieves abooleanvalue by key.- Specified by:
getAsBooleanin interfaceIValueMap- Parameters:
key- the keydefaultValue- the default to return- Returns:
- the value or defaultValue if value is not a valid boolean or no value is in this
IValueMap - See Also:
IValueMap.getAsBoolean(String, boolean)
-
getAsInteger
public java.lang.Integer getAsInteger(java.lang.String key)
Description copied from interface:IValueMapRetrieves anIntegervalue by key.- Specified by:
getAsIntegerin interfaceIValueMap- Parameters:
key- the key- Returns:
- the value or null if value is not a valid integer or no value is in this
IValueMap - See Also:
IValueMap.getAsInteger(String)
-
getAsInteger
public int getAsInteger(java.lang.String key, int defaultValue)Description copied from interface:IValueMapRetrieves anintegervalue by key.- Specified by:
getAsIntegerin interfaceIValueMap- Parameters:
key- the keydefaultValue- the default to return- Returns:
- the value or defaultValue if value is not a valid integer or no value is in this
IValueMap - See Also:
IValueMap.getAsInteger(String, int)
-
getAsLong
public java.lang.Long getAsLong(java.lang.String key)
Description copied from interface:IValueMapRetrieves aLongvalue by key.- Specified by:
getAsLongin interfaceIValueMap- Parameters:
key- the key- Returns:
- the value or null if value is not a valid long or no value is in this
IValueMap - See Also:
IValueMap.getAsLong(String)
-
getAsLong
public long getAsLong(java.lang.String key, long defaultValue)Description copied from interface:IValueMapRetrieves alongvalue by key.- Specified by:
getAsLongin interfaceIValueMap- Parameters:
key- the keydefaultValue- the default to return- Returns:
- the value or defaultValue if value is not a valid long or no value is in this
IValueMap - See Also:
IValueMap.getAsLong(String, long)
-
getAsDouble
public java.lang.Double getAsDouble(java.lang.String key)
Description copied from interface:IValueMapRetrieves aDoublevalue by key.- Specified by:
getAsDoublein interfaceIValueMap- Parameters:
key- the key- Returns:
- the value or null if value is not a valid double or no value is in this
IValueMap - See Also:
IValueMap.getAsDouble(String)
-
getAsDouble
public double getAsDouble(java.lang.String key, double defaultValue)Description copied from interface:IValueMapRetrieves adoublevalue by key.- Specified by:
getAsDoublein interfaceIValueMap- Parameters:
key- the keydefaultValue- the default to return- Returns:
- the value or defaultValue if value is not a valid double or no value is in this
IValueMap - See Also:
IValueMap.getAsDouble(String, double)
-
getAsDuration
public Duration getAsDuration(java.lang.String key)
Description copied from interface:IValueMapRetrieves aDurationvalue by key.- Specified by:
getAsDurationin interfaceIValueMap- Parameters:
key- the key- Returns:
- the value or null if value is not a valid Duration or no value is in this
IValueMap - See Also:
IValueMap.getAsDuration(String)
-
getAsDuration
public Duration getAsDuration(java.lang.String key, Duration defaultValue)
Description copied from interface:IValueMapRetrieves aDurationvalue by key.- Specified by:
getAsDurationin interfaceIValueMap- Parameters:
key- the keydefaultValue- the default to return- Returns:
- the value or defaultValue if value is not a valid Duration or no value is in this
IValueMap - See Also:
IValueMap.getAsDuration(String, Duration)
-
getAsTime
public Time getAsTime(java.lang.String key)
Description copied from interface:IValueMapRetrieves aTimevalue by key.- Specified by:
getAsTimein interfaceIValueMap- Parameters:
key- the key- Returns:
- the value or null if value is not a valid Time or no value is in this
IValueMap - See Also:
IValueMap.getAsTime(String)
-
getAsTime
public Time getAsTime(java.lang.String key, Time defaultValue)
Description copied from interface:IValueMapRetrieves aTimevalue by key.- Specified by:
getAsTimein interfaceIValueMap- Parameters:
key- the keydefaultValue- the default to return- Returns:
- the value or defaultValue if value is not a valid Time or no value is in this
IValueMap - See Also:
IValueMap.getAsTime(String, Time)
-
getAsEnum
public <T extends java.lang.Enum<T>> T getAsEnum(java.lang.String key, java.lang.Class<T> eClass)Description copied from interface:IValueMapRetrieves anEnumvalue by key.- Specified by:
getAsEnumin interfaceIValueMap- Type Parameters:
T- type of enum- Parameters:
key- the keyeClass- the enumeration class- Returns:
- the value or null if value is not a valid value of the Enumeration or no value is in
this
IValueMap - See Also:
IValueMap.getAsEnum(java.lang.String, java.lang.Class)
-
getAsEnum
public <T extends java.lang.Enum<T>> T getAsEnum(java.lang.String key, T defaultValue)Description copied from interface:IValueMapRetrieves anEnumvalue by key.- Specified by:
getAsEnumin interfaceIValueMap- Type Parameters:
T- type of enum- Parameters:
key- the keydefaultValue- the default value from the Enumeration (cannot be null)- Returns:
- the value or defaultValue if value is not a valid value of the Enumeration or no
value is in this
IValueMap - See Also:
IValueMap.getAsEnum(java.lang.String, java.lang.Enum)
-
getAsEnum
public <T extends java.lang.Enum<T>> T getAsEnum(java.lang.String key, java.lang.Class<T> eClass, T defaultValue)Description copied from interface:IValueMapRetrieves anEnumvalue by key.- Specified by:
getAsEnumin interfaceIValueMap- Type Parameters:
T- type of enum- Parameters:
key- the keyeClass- the enumeration classdefaultValue- the default value from the Enumeration (may be null)- Returns:
- the value or defaultValue if value is not a valid value of the Enumeration or no
value is in this
IValueMap - See Also:
IValueMap.getAsEnum(java.lang.String, java.lang.Class, java.lang.Enum)
-
-