public class ValueMap extends LinkedHashMap<String,Object> implements IValueMap
IValueMap implementation that holds values, parses Strings, and
exposes a variety of convenience methods.
In addition to a no-arg constructor and a copy constructor that takes a Map
argument, 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 ValueMap in the usual way or with methods that do
handy conversions to various types, including String, StringValue,
int, long, double, Time and
Duration.
The makeImmutable method will make the underlying Map immutable.
Further attempts to change the Map will result in a RuntimeException.
The toString method converts a ValueMap object to a readable key/value
string for diagnostics.
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>| Modifier and Type | Field and Description |
|---|---|
static ValueMap |
EMPTY_MAP
an empty
ValueMap. |
| Constructor and Description |
|---|
ValueMap()
Constructs empty
ValueMap. |
ValueMap(Map<? extends String,?> map)
Copy constructor.
|
ValueMap(String keyValuePairs)
Constructor.
|
ValueMap(String keyValuePairs,
String delimiter)
Constructor.
|
ValueMap(String keyValuePairs,
String delimiter,
MetaPattern valuePattern)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
Object |
add(String key,
String value)
Adds the value to this
ValueMap with the given key. |
void |
clear() |
Boolean |
getAsBoolean(String key)
Retrieves a
Boolean value by key. |
boolean |
getAsBoolean(String key,
boolean defaultValue)
Retrieves a
boolean value by key. |
Double |
getAsDouble(String key)
Retrieves a
Double value by key. |
double |
getAsDouble(String key,
double defaultValue)
Retrieves a
double value by key. |
Duration |
getAsDuration(String key)
Retrieves a
Duration value by key. |
Duration |
getAsDuration(String key,
Duration defaultValue)
Retrieves a
Duration value by key. |
<T extends Enum<T>> |
getAsEnum(String key,
Class<T> eClass)
Retrieves an
Enum value by key. |
<T extends Enum<T>> |
getAsEnum(String key,
Class<T> eClass,
T defaultValue)
Retrieves an
Enum value by key. |
<T extends Enum<T>> |
getAsEnum(String key,
T defaultValue)
Retrieves an
Enum value by key. |
Integer |
getAsInteger(String key)
Retrieves an
Integer value by key. |
int |
getAsInteger(String key,
int defaultValue)
Retrieves an
integer value by key. |
Long |
getAsLong(String key)
Retrieves a
Long value by key. |
long |
getAsLong(String key,
long defaultValue)
Retrieves a
long value by key. |
Time |
getAsTime(String key)
Retrieves a
Time value by key. |
Time |
getAsTime(String key,
Time defaultValue)
Retrieves a
Time value by key. |
boolean |
getBoolean(String key)
Retrieves a
boolean value by key. |
CharSequence |
getCharSequence(String key)
Retrieves a
CharSequence by key. |
double |
getDouble(String key)
Retrieves a
double value by key. |
double |
getDouble(String key,
double defaultValue)
Retrieves a
double value by key, using a default value if not found. |
Duration |
getDuration(String key)
Retrieves a
Duration by key. |
int |
getInt(String key)
Retrieves an
int value by key. |
int |
getInt(String key,
int defaultValue)
Retrieves an
int value by key, using a default value if not found. |
String |
getKey(String key)
Provided that the hash key is a
String and 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. |
long |
getLong(String key)
Retrieves a
long value by key. |
long |
getLong(String key,
long defaultValue)
Retrieves a
long value by key, using a default value if not found. |
String |
getString(String key)
Retrieves a
String by key. |
String |
getString(String key,
String defaultValue)
Retrieves a
String by key, using a default value if not found. |
String[] |
getStringArray(String key)
Retrieves a
String array by key. |
StringValue |
getStringValue(String key)
Retrieves a
StringValue object by key. |
Time |
getTime(String key)
Retrieves a
Time object by key. |
boolean |
isImmutable()
Returns whether or not this
IValueMap is immutable. |
IValueMap |
makeImmutable()
Makes this
IValueMap immutable by changing the underlying map representation to
a Collections.unmodifiableMap. |
Object |
put(String key,
Object value) |
void |
putAll(Map<? extends String,?> map) |
Object |
remove(Object key) |
String |
toString()
Generates a
String representation of this object. |
containsValue, get, removeEldestEntryclone, containsKey, entrySet, isEmpty, keySet, size, valuesequals, hashCodepublic static final ValueMap EMPTY_MAP
ValueMap.public ValueMap()
ValueMap.public ValueMap(Map<? extends String,?> map)
map - the ValueMap to copypublic ValueMap(String keyValuePairs)
NOTE: Please use RequestUtils.decodeParameters() if you wish to properly decode
a request URL.
keyValuePairs - list of key/value pairs separated by commas. For example, "
param1=foo,param2=bar"public ValueMap(String keyValuePairs, String delimiter)
NOTE: Please use RequestUtils.decodeParameters() if you wish to properly decode
a request URL.
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 pairspublic ValueMap(String keyValuePairs, String delimiter, MetaPattern valuePattern)
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)".public final void clear()
clear in interface Map<String,Object>clear in class LinkedHashMap<String,Object>Map.clear()public final boolean getBoolean(String key) throws StringValueConversionException
IValueMapboolean value by key.getBoolean in interface IValueMapkey - the keyStringValueConversionExceptionIValueMap.getBoolean(String)public final double getDouble(String key) throws StringValueConversionException
IValueMapdouble value by key.getDouble in interface IValueMapkey - the keyStringValueConversionExceptionIValueMap.getDouble(String)public final double getDouble(String key, double defaultValue)
IValueMapdouble value by key, using a default value if not found.getDouble in interface IValueMapkey - the keydefaultValue - value to use if no value is in this IValueMapIValueMap.getDouble(String, double)public final Duration getDuration(String key) throws StringValueConversionException
IValueMapDuration by key.getDuration in interface IValueMapkey - the keyDuration valueStringValueConversionExceptionIValueMap.getDuration(String)public final int getInt(String key) throws StringValueConversionException
IValueMapint value by key.getInt in interface IValueMapkey - the keyStringValueConversionExceptionIValueMap.getInt(String)public final int getInt(String key, int defaultValue)
IValueMapint value by key, using a default value if not found.getInt in interface IValueMapkey - the keydefaultValue - value to use if no value is in this IValueMapIValueMap.getInt(String, int)public final long getLong(String key) throws StringValueConversionException
IValueMaplong value by key.getLong in interface IValueMapkey - the keyStringValueConversionExceptionIValueMap.getLong(String)public final long getLong(String key, long defaultValue)
IValueMaplong value by key, using a default value if not found.getLong in interface IValueMapkey - the keydefaultValue - value to use if no value in this IValueMapIValueMap.getLong(String, long)public final String getString(String key, String defaultValue)
IValueMapString by key, using a default value if not found.getString in interface IValueMapkey - the keydefaultValue - default value to return if value is nullStringIValueMap.getString(String, String)public final String getString(String key)
IValueMapString by key.getString in interface IValueMapkey - the keyStringIValueMap.getString(String)public final CharSequence getCharSequence(String key)
IValueMapCharSequence by key.getCharSequence in interface IValueMapkey - the keyCharSequenceIValueMap.getCharSequence(String)public String[] getStringArray(String key)
IValueMapString array by key. If the value was a String[] it
will be returned directly. If it was a String it will be converted to a
String array of length one. If it was an array of another type, a
String array will be made and each element will be converted to a
String.getStringArray in interface IValueMapkey - the keyString array of that keyIValueMap.getStringArray(String)public StringValue getStringValue(String key)
IValueMapStringValue object by key.getStringValue in interface IValueMapkey - the keyStringValue objectIValueMap.getStringValue(String)public final Time getTime(String key) throws StringValueConversionException
IValueMapTime object by key.getTime in interface IValueMapkey - the keyTime objectStringValueConversionExceptionIValueMap.getTime(String)public final boolean isImmutable()
IValueMapIValueMap is immutable.isImmutable in interface IValueMapIValueMap is immutableIValueMap.isImmutable()public final IValueMap makeImmutable()
IValueMapIValueMap immutable by changing the underlying map representation to
a Collections.unmodifiableMap. After calling this method, any attempt to modify
this IValueMap will result in a RuntimeException being thrown by
the Collections framework.makeImmutable in interface IValueMapIValueMapIValueMap.makeImmutable()public final Object add(String key, String value)
ValueMap with the given key. If the key already is in the
ValueMap it will combine the values into a String array, else it
will just store the value itself.key - the key to store the value undervalue - the value that must be added/merged to the ValueMapString array with
the combined valuespublic String getKey(String key)
IValueMapString and 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.getKey in interface IValueMapkey - the keyIValueMap.getKey(String)public String toString()
String representation of this object.toString in class AbstractMap<String,Object>String representation of this ValueMap consistent with the
tag-attribute style of markup elements. For example: a="x" b="y" c="z".public Boolean getAsBoolean(String key)
IValueMapBoolean value by key.getAsBoolean in interface IValueMapkey - the keyIValueMapIValueMap.getAsBoolean(String)public boolean getAsBoolean(String key, boolean defaultValue)
IValueMapboolean value by key.getAsBoolean in interface IValueMapkey - the keydefaultValue - the default to returnIValueMapIValueMap.getAsBoolean(String, boolean)public Integer getAsInteger(String key)
IValueMapInteger value by key.getAsInteger in interface IValueMapkey - the keyIValueMapIValueMap.getAsInteger(String)public int getAsInteger(String key, int defaultValue)
IValueMapinteger value by key.getAsInteger in interface IValueMapkey - the keydefaultValue - the default to returnIValueMapIValueMap.getAsInteger(String, int)public Long getAsLong(String key)
IValueMapLong value by key.getAsLong in interface IValueMapkey - the keyIValueMapIValueMap.getAsLong(String)public long getAsLong(String key, long defaultValue)
IValueMaplong value by key.getAsLong in interface IValueMapkey - the keydefaultValue - the default to returnIValueMapIValueMap.getAsLong(String, long)public Double getAsDouble(String key)
IValueMapDouble value by key.getAsDouble in interface IValueMapkey - the keyIValueMapIValueMap.getAsDouble(String)public double getAsDouble(String key, double defaultValue)
IValueMapdouble value by key.getAsDouble in interface IValueMapkey - the keydefaultValue - the default to returnIValueMapIValueMap.getAsDouble(String, double)public Duration getAsDuration(String key)
IValueMapDuration value by key.getAsDuration in interface IValueMapkey - the keyIValueMapIValueMap.getAsDuration(String)public Duration getAsDuration(String key, Duration defaultValue)
IValueMapDuration value by key.getAsDuration in interface IValueMapkey - the keydefaultValue - the default to returnIValueMapIValueMap.getAsDuration(String, Duration)public Time getAsTime(String key)
IValueMapTime value by key.getAsTime in interface IValueMapkey - the keyIValueMapIValueMap.getAsTime(String)public Time getAsTime(String key, Time defaultValue)
IValueMapTime value by key.getAsTime in interface IValueMapkey - the keydefaultValue - the default to returnIValueMapIValueMap.getAsTime(String, Time)public <T extends Enum<T>> T getAsEnum(String key, Class<T> eClass)
IValueMapEnum value by key.getAsEnum in interface IValueMapT - type of enumkey - the keyeClass - the enumeration classIValueMapIValueMap.getAsEnum(java.lang.String, java.lang.Class)public <T extends Enum<T>> T getAsEnum(String key, T defaultValue)
IValueMapEnum value by key.getAsEnum in interface IValueMapT - type of enumkey - the keydefaultValue - the default value from the Enumeration (cannot be null)IValueMapIValueMap.getAsEnum(java.lang.String, java.lang.Enum)public <T extends Enum<T>> T getAsEnum(String key, Class<T> eClass, T defaultValue)
IValueMapEnum value by key.getAsEnum in interface IValueMapT - type of enumkey - the keyeClass - the enumeration classdefaultValue - the default value from the Enumeration (may be null)IValueMapIValueMap.getAsEnum(java.lang.String, java.lang.Class,
java.lang.Enum)Copyright © 2006-2012 Apache Software Foundation. All Rights Reserved.