|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.util.AbstractMap<K,V> java.util.HashMap org.apache.wicket.util.value.ValueMap
public class ValueMap
A IValueMap
implementation that holds values, parses String
s, and
exposes a variety of convenience methods.
In addition to a no-arg constructor and a copy constructor that takes a Map
argument, ValueMap
s 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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class java.util.AbstractMap |
---|
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V> |
Nested classes/interfaces inherited from interface java.util.Map |
---|
java.util.Map.Entry<K,V> |
Field Summary | |
---|---|
static ValueMap |
EMPTY_MAP
an empty ValueMap . |
Constructor Summary | |
---|---|
ValueMap()
Constructs empty ValueMap . |
|
ValueMap(java.util.Map map)
Copy constructor. |
|
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. |
Method Summary | |
---|---|
java.lang.Object |
add(java.lang.String key,
java.lang.String value)
Adds the value to this ValueMap with the given key. |
void |
clear()
|
boolean |
getBoolean(java.lang.String key)
Retrieves a boolean value by key. |
java.lang.CharSequence |
getCharSequence(java.lang.String key)
Retrieves a CharSequence by key. |
double |
getDouble(java.lang.String key)
Retrieves a double value by key. |
double |
getDouble(java.lang.String key,
double defaultValue)
Retrieves a double value by key, using a default value if not found. |
Duration |
getDuration(java.lang.String key)
Retrieves a Duration by key. |
int |
getInt(java.lang.String key)
Retrieves an int value by key. |
int |
getInt(java.lang.String key,
int defaultValue)
Retrieves an int value by key, using a default value if not found. |
java.lang.String |
getKey(java.lang.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(java.lang.String key)
Retrieves a long value by key. |
long |
getLong(java.lang.String key,
long defaultValue)
Retrieves a long value by key, using a default value if not found. |
java.lang.String |
getString(java.lang.String key)
Retrieves a String by key. |
java.lang.String |
getString(java.lang.String key,
java.lang.String defaultValue)
Retrieves a String by key, using a default value if not found. |
java.lang.String[] |
getStringArray(java.lang.String key)
Retrieves a String array by key. |
StringValue |
getStringValue(java.lang.String key)
Retrieves a StringValue object by key. |
Time |
getTime(java.lang.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 . |
java.lang.Object |
put(java.lang.Object key,
java.lang.Object value)
|
void |
putAll(java.util.Map map)
|
java.lang.Object |
remove(java.lang.Object key)
|
java.lang.String |
toString()
Generates a String representation of this object. |
Methods inherited from class java.util.HashMap |
---|
clone, containsKey, containsValue, entrySet, get, isEmpty, keySet, size, values |
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 |
---|
containsKey, containsValue, entrySet, equals, get, hashCode, isEmpty, keySet, size, values |
Field Detail |
---|
public static final ValueMap EMPTY_MAP
ValueMap
.
Constructor Detail |
---|
public ValueMap()
ValueMap
.
public ValueMap(java.util.Map map)
map
- the ValueMap
to copypublic ValueMap(java.lang.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(java.lang.String keyValuePairs, java.lang.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(java.lang.String keyValuePairs, java.lang.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)
".Method Detail |
---|
public final void clear()
clear
in interface java.util.Map
clear
in interface IValueMap
clear
in class java.util.HashMap
Map.clear()
public final boolean getBoolean(java.lang.String key) throws StringValueConversionException
IValueMap
boolean
value by key.
getBoolean
in interface IValueMap
key
- the key
StringValueConversionException
IValueMap.getBoolean(String)
public final double getDouble(java.lang.String key) throws StringValueConversionException
IValueMap
double
value by key.
getDouble
in interface IValueMap
key
- the key
StringValueConversionException
IValueMap.getDouble(String)
public final double getDouble(java.lang.String key, double defaultValue) throws StringValueConversionException
IValueMap
double
value by key, using a default value if not found.
getDouble
in interface IValueMap
key
- the keydefaultValue
- value to use if no value is in this IValueMap
StringValueConversionException
IValueMap.getDouble(String, double)
public final Duration getDuration(java.lang.String key) throws StringValueConversionException
IValueMap
Duration
by key.
getDuration
in interface IValueMap
key
- the key
Duration
value
StringValueConversionException
IValueMap.getDuration(String)
public final int getInt(java.lang.String key) throws StringValueConversionException
IValueMap
int
value by key.
getInt
in interface IValueMap
key
- the key
StringValueConversionException
IValueMap.getInt(String)
public final int getInt(java.lang.String key, int defaultValue) throws StringValueConversionException
IValueMap
int
value by key, using a default value if not found.
getInt
in interface IValueMap
key
- the keydefaultValue
- value to use if no value is in this IValueMap
StringValueConversionException
IValueMap.getInt(String, int)
public final long getLong(java.lang.String key) throws StringValueConversionException
IValueMap
long
value by key.
getLong
in interface IValueMap
key
- the key
StringValueConversionException
IValueMap.getLong(String)
public final long getLong(java.lang.String key, long defaultValue) throws StringValueConversionException
IValueMap
long
value by key, using a default value if not found.
getLong
in interface IValueMap
key
- the keydefaultValue
- value to use if no value in this IValueMap
StringValueConversionException
IValueMap.getLong(String, long)
public final java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
IValueMap
String
by key, using a default value if not found.
getString
in interface IValueMap
key
- the keydefaultValue
- default value to return if value is null
String
IValueMap.getString(String, String)
public final java.lang.String getString(java.lang.String key)
IValueMap
String
by key.
getString
in interface IValueMap
key
- the key
String
IValueMap.getString(String)
public final java.lang.CharSequence getCharSequence(java.lang.String key)
IValueMap
CharSequence
by key.
getCharSequence
in interface IValueMap
key
- the key
CharSequence
IValueMap.getCharSequence(String)
public java.lang.String[] getStringArray(java.lang.String key)
IValueMap
String
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 IValueMap
key
- the key
String
array of that keyIValueMap.getStringArray(String)
public StringValue getStringValue(java.lang.String key)
IValueMap
StringValue
object by key.
getStringValue
in interface IValueMap
key
- the key
StringValue
objectIValueMap.getStringValue(String)
public final Time getTime(java.lang.String key) throws StringValueConversionException
IValueMap
Time
object by key.
getTime
in interface IValueMap
key
- the key
Time
object
StringValueConversionException
IValueMap.getTime(String)
public final boolean isImmutable()
IValueMap
IValueMap
is immutable.
isImmutable
in interface IValueMap
IValueMap
is immutableIValueMap.isImmutable()
public final IValueMap makeImmutable()
IValueMap
IValueMap
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 IValueMap
IValueMap
IValueMap.makeImmutable()
public java.lang.Object put(java.lang.Object key, java.lang.Object value)
put
in interface java.util.Map
put
in interface IValueMap
put
in class java.util.HashMap
Map.put(java.lang.Object, java.lang.Object)
public final java.lang.Object add(java.lang.String key, java.lang.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 ValueMap
String
array
with the combined valuespublic void putAll(java.util.Map map)
putAll
in interface java.util.Map
putAll
in interface IValueMap
putAll
in class java.util.HashMap
Map.putAll(java.util.Map)
public java.lang.Object remove(java.lang.Object key)
remove
in interface java.util.Map
remove
in interface IValueMap
remove
in class java.util.HashMap
Map.remove(java.lang.Object)
public java.lang.String getKey(java.lang.String key)
IValueMap
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.
getKey
in interface IValueMap
key
- the key
IValueMap.getKey(String)
public java.lang.String toString()
String
representation of this object.
toString
in class java.util.AbstractMap
String
representation of this ValueMap
consistent with
the tag-attribute style of markup elements. For example:
a="x" b="y" c="z"
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |