wicket.util.value
Class ValueMap

java.lang.Object
  extended bywicket.util.value.ValueMap
All Implemented Interfaces:
java.util.Map, java.io.Serializable
Direct Known Subclasses:
LowerCaseKeyValueMap, PageParameters

public class ValueMap
extends java.lang.Object
implements java.util.Map, java.io.Serializable

A Map 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 map 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 runtime exception.

The toString() method converts a ValueMap object to a readable key/value string for diagnostics.

Author:
Jonathan Locke
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.util.Map
java.util.Map.Entry
 
Field Summary
static ValueMap EMPTY_MAP
          An empty ValueMap.
 
Constructor Summary
ValueMap()
          Constructs empty value map.
ValueMap(java.util.Map map)
          Copy constructor.
ValueMap(java.lang.String keyValuePairs)
          Constructor.
ValueMap(java.lang.String keyValuePairs, java.lang.String delimiter)
          Constructor.
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set entrySet()
           
 java.lang.Object get(java.lang.Object key)
           
 double getDouble(java.lang.String key)
          Gets a double value by key.
 Duration getDuration(java.lang.String key)
          Gets a duration.
 int getInt(java.lang.String key)
          Gets an int.
 int getInt(java.lang.String key, int defaultValue)
          Gets an int, using a default if not found.
 long getLong(java.lang.String key)
          Gets a long.
 long getLong(java.lang.String key, long defaultValue)
          Gets a long using a default if not found.
 java.lang.String getString(java.lang.String key)
          Gets a string by key.
 StringValue getStringValue(java.lang.String key)
          Gets a StringValue by key.
 Time getTime(java.lang.String key)
          Gets a time.
 boolean isEmpty()
           
 java.util.Set keySet()
           
 void makeImmutable()
          Makes this value map 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 t)
           
 java.lang.Object remove(java.lang.Object key)
           
 int size()
           
 java.lang.String toDebugString()
           
 java.lang.String toString()
          Gets a string representation of this object
 java.util.Collection values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Field Detail

EMPTY_MAP

public static final ValueMap EMPTY_MAP
An empty ValueMap.

Constructor Detail

ValueMap

public ValueMap()
Constructs empty value map.


ValueMap

public ValueMap(java.util.Map map)
Copy constructor.

Parameters:
map - The map to copy

ValueMap

public ValueMap(java.lang.String keyValuePairs)
Constructor.

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.

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 pairs
Method Detail

clear

public final void clear()
Specified by:
clear in interface java.util.Map
See Also:
Map.clear()

containsKey

public boolean containsKey(java.lang.Object key)
Specified by:
containsKey in interface java.util.Map
See Also:
Map.containsKey(java.lang.Object)

containsValue

public final boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map
See Also:
Map.containsValue(java.lang.Object)

entrySet

public final java.util.Set entrySet()
Specified by:
entrySet in interface java.util.Map
See Also:
Map.entrySet()

get

public java.lang.Object get(java.lang.Object key)
Specified by:
get in interface java.util.Map
See Also:
Map.get(java.lang.Object)

getDouble

public final double getDouble(java.lang.String key)
                       throws StringValueConversionException
Gets a double value by key.

Parameters:
key - The key
Returns:
The value
Throws:
StringValueConversionException

getDuration

public final Duration getDuration(java.lang.String key)
                           throws StringValueConversionException
Gets a duration.

Parameters:
key - The key
Returns:
The value
Throws:
StringValueConversionException

getInt

public final int getInt(java.lang.String key)
                 throws StringValueConversionException
Gets an int.

Parameters:
key - The key
Returns:
The value
Throws:
StringValueConversionException

getInt

public final int getInt(java.lang.String key,
                        int defaultValue)
                 throws StringValueConversionException
Gets an int, using a default if not found.

Parameters:
key - The key
defaultValue - Value to use if no value in map
Returns:
The value
Throws:
StringValueConversionException

getLong

public final long getLong(java.lang.String key)
                   throws StringValueConversionException
Gets a long.

Parameters:
key - The key
Returns:
The value
Throws:
StringValueConversionException

getLong

public final long getLong(java.lang.String key,
                          long defaultValue)
                   throws StringValueConversionException
Gets a long using a default if not found.

Parameters:
key - The key
defaultValue - Value to use if no value in map
Returns:
The value
Throws:
StringValueConversionException

getString

public final java.lang.String getString(java.lang.String key)
Gets a string by key.

Parameters:
key - The get
Returns:
The string

getStringValue

public StringValue getStringValue(java.lang.String key)
Gets a StringValue by key.

Parameters:
key - The key
Returns:
The string value object

getTime

public final Time getTime(java.lang.String key)
                   throws StringValueConversionException
Gets a time.

Parameters:
key - The key
Returns:
The value
Throws:
StringValueConversionException

isEmpty

public final boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map
See Also:
Map.isEmpty()

keySet

public final java.util.Set keySet()
Specified by:
keySet in interface java.util.Map
See Also:
Map.keySet()

makeImmutable

public final void makeImmutable()
Makes this value map immutable by changing the underlying map representation to a collections "unmodifiableMap". After calling this method, any attempt to modify this map will result in a runtime exception being thrown by the collections classes.


put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Specified by:
put in interface java.util.Map
See Also:
Map.put(java.lang.Object, java.lang.Object)

putAll

public void putAll(java.util.Map t)
Specified by:
putAll in interface java.util.Map
See Also:
Map.putAll(java.util.Map)

remove

public java.lang.Object remove(java.lang.Object key)
Specified by:
remove in interface java.util.Map
See Also:
Map.remove(java.lang.Object)

size

public final int size()
Specified by:
size in interface java.util.Map
See Also:
Map.size()

toDebugString

public final java.lang.String toDebugString()
Returns:
Debug string representation of this map

toString

public java.lang.String toString()
Gets a string representation of this object

Returns:
String representation of map consistent with tag attribute style of markup elements, for example: a="x" b="y" c="z"

values

public final java.util.Collection values()
Specified by:
values in interface java.util.Map
See Also:
Map.values()


Copyright © 2004-2005 Wicket developers. All Rights Reserved.