Class ValueMap
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<K,V>
-
- java.util.LinkedHashMap<String,Object>
-
- org.apache.wicket.util.value.ValueMap
-
- Direct Known Subclasses:
AttributeMap
public class ValueMap extends LinkedHashMap<String,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
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object>
-
-
Constructor Summary
Constructors Constructor Description ValueMap()Constructs emptyValueMap.ValueMap(String keyValuePairs)Constructor.ValueMap(String keyValuePairs, String delimiter)Constructor.ValueMap(String keyValuePairs, String delimiter, MetaPattern valuePattern)Constructor.ValueMap(Map<? extends String,?> map)Copy constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Objectadd(String key, String value)Adds the value to thisValueMapwith the given key.voidclear()BooleangetAsBoolean(String key)Retrieves aBooleanvalue by key.booleangetAsBoolean(String key, boolean defaultValue)Retrieves abooleanvalue by key.DoublegetAsDouble(String key)Retrieves aDoublevalue by key.doublegetAsDouble(String key, double defaultValue)Retrieves adoublevalue by key.DurationgetAsDuration(String key)Retrieves aDurationvalue by key.DurationgetAsDuration(String key, Duration defaultValue)Retrieves aDurationvalue by key.<T extends Enum<T>>
TgetAsEnum(String key, Class<T> eClass)Retrieves anEnumvalue by key.<T extends Enum<T>>
TgetAsEnum(String key, Class<T> eClass, T defaultValue)Retrieves anEnumvalue by key.<T extends Enum<T>>
TgetAsEnum(String key, T defaultValue)Retrieves anEnumvalue by key.InstantgetAsInstant(String key)Retrieves aTimevalue by key.IntegergetAsInteger(String key)Retrieves anIntegervalue by key.intgetAsInteger(String key, int defaultValue)Retrieves anintegervalue by key.LonggetAsLong(String key)Retrieves aLongvalue by key.longgetAsLong(String key, long defaultValue)Retrieves alongvalue by key.InstantgetAsTime(String key, Instant defaultValue)Retrieves aTimevalue by key.booleangetBoolean(String key)Retrieves abooleanvalue by key.CharSequencegetCharSequence(String key)Retrieves aCharSequenceby key.doublegetDouble(String key)Retrieves adoublevalue by key.doublegetDouble(String key, double defaultValue)Retrieves adoublevalue by key, using a default value if not found.DurationgetDuration(String key)Retrieves aDurationby key.InstantgetInstant(String key)Retrieves aInstantobject by key.intgetInt(String key)Retrieves anintvalue by key.intgetInt(String key, int defaultValue)Retrieves anintvalue by key, using a default value if not found.StringgetKey(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(String key)Retrieves alongvalue by key.longgetLong(String key, long defaultValue)Retrieves alongvalue by key, using a default value if not found.StringgetString(String key)Retrieves aStringby key.StringgetString(String key, String defaultValue)Retrieves aStringby key, using a default value if not found.String[]getStringArray(String key)Retrieves aStringarray by key.StringValuegetStringValue(String key)Retrieves aStringValueobject by key.booleanisImmutable()Returns whether or not thisIValueMapis immutable.IValueMapmakeImmutable()Makes thisIValueMapimmutable by changing the underlying map representation to aCollections.unmodifiableMap.Objectput(String key, Object value)voidputAll(Map<? extends String,?> map)Objectremove(Object key)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
-
Methods inherited from class java.util.AbstractMap
equals, hashCode
-
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll, size, values
-
-
-
-
Constructor Detail
-
ValueMap
public ValueMap()
Constructs emptyValueMap.
-
ValueMap
public ValueMap(Map<? extends String,?> map)
Copy constructor.- Parameters:
map- theValueMapto copy
-
ValueMap
public ValueMap(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(String keyValuePairs, 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(String keyValuePairs, 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()
-
getBoolean
public final boolean getBoolean(String key) throws StringValueConversionException
Description copied from interface:IValueMapRetrieves abooleanvalue by key.- Specified by:
getBooleanin interfaceIValueMap- Parameters:
key- the key- Returns:
- the value
- Throws:
StringValueConversionException
-
getDouble
public final double getDouble(String key) throws StringValueConversionException
Description copied from interface:IValueMapRetrieves adoublevalue by key.- Specified by:
getDoublein interfaceIValueMap- Parameters:
key- the key- Returns:
- the value
- Throws:
StringValueConversionException
-
getDouble
public final double getDouble(String key, double defaultValue)
Description copied from interface:IValueMapRetrieves adoublevalue by key, using a default value if not found.
-
getDuration
public final Duration getDuration(String key) throws StringValueConversionException
Description copied from interface:IValueMapRetrieves aDurationby key.- Specified by:
getDurationin interfaceIValueMap- Parameters:
key- the key- Returns:
- the
Durationvalue - Throws:
StringValueConversionException
-
getInt
public final int getInt(String key) throws StringValueConversionException
Description copied from interface:IValueMapRetrieves anintvalue by key.- Specified by:
getIntin interfaceIValueMap- Parameters:
key- the key- Returns:
- the value
- Throws:
StringValueConversionException
-
getInt
public final int getInt(String key, int defaultValue)
Description copied from interface:IValueMapRetrieves anintvalue by key, using a default value if not found.
-
getLong
public final long getLong(String key) throws StringValueConversionException
Description copied from interface:IValueMapRetrieves alongvalue by key.- Specified by:
getLongin interfaceIValueMap- Parameters:
key- the key- Returns:
- the value
- Throws:
StringValueConversionException
-
getLong
public final long getLong(String key, long defaultValue)
Description copied from interface:IValueMapRetrieves alongvalue by key, using a default value if not found.
-
getString
public final String getString(String key, String defaultValue)
Description copied from interface:IValueMapRetrieves aStringby key, using a default value if not found.
-
getString
public final String getString(String key)
Description copied from interface:IValueMapRetrieves aStringby key.
-
getCharSequence
public final CharSequence getCharSequence(String key)
Description copied from interface:IValueMapRetrieves aCharSequenceby key.- Specified by:
getCharSequencein interfaceIValueMap- Parameters:
key- the key- Returns:
- the
CharSequence
-
getStringArray
public String[] getStringArray(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
-
getStringValue
public StringValue getStringValue(String key)
Description copied from interface:IValueMapRetrieves aStringValueobject by key.- Specified by:
getStringValuein interfaceIValueMap- Parameters:
key- the key- Returns:
- the
StringValueobject
-
getInstant
public final Instant getInstant(String key) throws StringValueConversionException
Description copied from interface:IValueMapRetrieves aInstantobject by key.- Specified by:
getInstantin interfaceIValueMap- Parameters:
key- the key- Returns:
- the
Instantobject - Throws:
StringValueConversionException
-
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
-
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
-
add
public final Object add(String key, 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
-
getKey
public String getKey(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.
-
toString
public String toString()
Generates aStringrepresentation of this object.- Overrides:
toStringin classAbstractMap<String,Object>- Returns:
Stringrepresentation of thisValueMapconsistent with the tag-attribute style of markup elements. For example:a="x" b="y" c="z".
-
getAsBoolean
public Boolean getAsBoolean(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
-
getAsBoolean
public boolean getAsBoolean(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
-
getAsInteger
public Integer getAsInteger(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
-
getAsInteger
public int getAsInteger(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
-
getAsLong
public Long getAsLong(String key)
Description copied from interface:IValueMapRetrieves aLongvalue by key.
-
getAsLong
public long getAsLong(String key, long defaultValue)
Description copied from interface:IValueMapRetrieves alongvalue by key.
-
getAsDouble
public Double getAsDouble(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
-
getAsDouble
public double getAsDouble(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
-
getAsDuration
public Duration getAsDuration(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
-
getAsDuration
public Duration getAsDuration(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
-
getAsInstant
public Instant getAsInstant(String key)
Description copied from interface:IValueMapRetrieves aTimevalue by key.- Specified by:
getAsInstantin interfaceIValueMap- Parameters:
key- the key- Returns:
- the value or null if value is not a valid Time or no value is in this
IValueMap
-
getAsTime
public Instant getAsTime(String key, Instant defaultValue)
Description copied from interface:IValueMapRetrieves aTimevalue by key.
-
getAsEnum
public <T extends Enum<T>> T getAsEnum(String key, Class<T> eClass)
Description copied from interface:IValueMapRetrieves anEnumvalue by key.
-
getAsEnum
public <T extends Enum<T>> T getAsEnum(String key, T defaultValue)
Description copied from interface:IValueMapRetrieves anEnumvalue by key.
-
getAsEnum
public <T extends Enum<T>> T getAsEnum(String key, 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
-
-