org.apache.wicket.util.value
Class CopyOnWriteValueMap

java.lang.Object
  extended by org.apache.wicket.util.value.CopyOnWriteValueMap
All Implemented Interfaces:
java.io.Serializable, java.util.Map<java.lang.String,java.lang.Object>, IValueMap

public class CopyOnWriteValueMap
extends java.lang.Object
implements IValueMap, java.io.Serializable

An implementation of IValueMap that makes a copy when a caller tries to change an immutable Map. That is, the Map may or may not be immutable, but if it is, a copy is made.

Since:
1.2.6
Author:
Johan Compagner, Doug Donohoe
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
java.util.Map.Entry<K,V>
 
Constructor Summary
CopyOnWriteValueMap(IValueMap wrapped)
          Constructor.
 
Method Summary
 void clear()
           
 boolean containsKey(java.lang.Object key)
           
 boolean containsValue(java.lang.Object value)
           
 java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
           
 boolean equals(java.lang.Object o)
           
 java.lang.Object get(java.lang.Object key)
           
 java.lang.Boolean getAsBoolean(java.lang.String key)
          Retrieves a Boolean value by key.
 boolean getAsBoolean(java.lang.String key, boolean defaultValue)
          Retrieves a boolean value by key.
 java.lang.Double getAsDouble(java.lang.String key)
          Retrieves a Double value by key.
 double getAsDouble(java.lang.String key, double defaultValue)
          Retrieves a double value by key.
 Duration getAsDuration(java.lang.String key)
          Retrieves a Duration value by key.
 Duration getAsDuration(java.lang.String key, Duration defaultValue)
          Retrieves a Duration value by key.
<T extends java.lang.Enum<T>>
T
getAsEnum(java.lang.String key, java.lang.Class<T> eClass)
          Retrieves an Enum value by key.
<T extends java.lang.Enum<T>>
T
getAsEnum(java.lang.String key, java.lang.Class<T> eClass, T defaultValue)
          Retrieves an Enum value by key.
<T extends java.lang.Enum<T>>
T
getAsEnum(java.lang.String key, T defaultValue)
          Retrieves an Enum value by key.
 java.lang.Integer getAsInteger(java.lang.String key)
          Retrieves an Integer value by key.
 int getAsInteger(java.lang.String key, int defaultValue)
          Retrieves an integer value by key.
 java.lang.Long getAsLong(java.lang.String key)
          Retrieves a Long value by key.
 long getAsLong(java.lang.String key, long defaultValue)
          Retrieves a long value by key.
 Time getAsTime(java.lang.String key)
          Retrieves a Time value by key.
 Time getAsTime(java.lang.String key, Time defaultValue)
          Retrieves a Time value by key.
 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 isEmpty()
           
 boolean isImmutable()
          Returns whether or not this IValueMap is immutable.
 java.util.Set<java.lang.String> keySet()
           
 IValueMap makeImmutable()
          Makes this IValueMap immutable by changing the underlying map representation to a Collections.unmodifiableMap.
 java.lang.Object put(java.lang.String key, java.lang.Object value)
           
 void putAll(java.util.Map<? extends java.lang.String,?> map)
           
 java.lang.Object remove(java.lang.Object key)
           
 int size()
           
 java.lang.String toString()
           
 java.util.Collection<java.lang.Object> values()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
hashCode
 

Constructor Detail

CopyOnWriteValueMap

public CopyOnWriteValueMap(IValueMap wrapped)
Constructor.

Parameters:
wrapped - the wrapped IValueMap
Method Detail

clear

public void clear()
Specified by:
clear in interface java.util.Map<java.lang.String,java.lang.Object>
See Also:
Map.clear()

containsKey

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

containsValue

public boolean containsValue(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<java.lang.String,java.lang.Object>
See Also:
Map.containsValue(Object)

entrySet

public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
Specified by:
entrySet in interface java.util.Map<java.lang.String,java.lang.Object>
See Also:
Map.entrySet()

equals

public boolean equals(java.lang.Object o)
Specified by:
equals in interface java.util.Map<java.lang.String,java.lang.Object>
Overrides:
equals in class java.lang.Object
See Also:
Map.equals(Object)

get

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

getBoolean

public boolean getBoolean(java.lang.String key)
                   throws StringValueConversionException
Description copied from interface: IValueMap
Retrieves a boolean value by key.

Specified by:
getBoolean in interface IValueMap
Parameters:
key - the key
Returns:
the value
Throws:
StringValueConversionException
See Also:
IValueMap.getBoolean(String)

getCharSequence

public java.lang.CharSequence getCharSequence(java.lang.String key)
Description copied from interface: IValueMap
Retrieves a CharSequence by key.

Specified by:
getCharSequence in interface IValueMap
Parameters:
key - the key
Returns:
the CharSequence
See Also:
IValueMap.getCharSequence(String)

getDouble

public double getDouble(java.lang.String key)
                 throws StringValueConversionException
Description copied from interface: IValueMap
Retrieves a double value by key.

Specified by:
getDouble in interface IValueMap
Parameters:
key - the key
Returns:
the value
Throws:
StringValueConversionException
See Also:
IValueMap.getDouble(String)

getDouble

public double getDouble(java.lang.String key,
                        double defaultValue)
                 throws StringValueConversionException
Description copied from interface: IValueMap
Retrieves a double value by key, using a default value if not found.

Specified by:
getDouble in interface IValueMap
Parameters:
key - the key
defaultValue - value to use if no value is in this IValueMap
Returns:
the value
Throws:
StringValueConversionException
See Also:
IValueMap.getDouble(String, double)

getDuration

public Duration getDuration(java.lang.String key)
                     throws StringValueConversionException
Description copied from interface: IValueMap
Retrieves a Duration by key.

Specified by:
getDuration in interface IValueMap
Parameters:
key - the key
Returns:
the Duration value
Throws:
StringValueConversionException
See Also:
IValueMap.getDuration(String)

getInt

public int getInt(java.lang.String key,
                  int defaultValue)
           throws StringValueConversionException
Description copied from interface: IValueMap
Retrieves an int value by key, using a default value if not found.

Specified by:
getInt in interface IValueMap
Parameters:
key - the key
defaultValue - value to use if no value is in this IValueMap
Returns:
the value
Throws:
StringValueConversionException
See Also:
IValueMap.getInt(String, int)

getInt

public int getInt(java.lang.String key)
           throws StringValueConversionException
Description copied from interface: IValueMap
Retrieves an int value by key.

Specified by:
getInt in interface IValueMap
Parameters:
key - the key
Returns:
the value
Throws:
StringValueConversionException
See Also:
IValueMap.getInt(String)

getKey

public java.lang.String getKey(java.lang.String key)
Description copied from interface: IValueMap
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.

Specified by:
getKey in interface IValueMap
Parameters:
key - the key
Returns:
the key with the correct writing
See Also:
IValueMap.getKey(String)

getLong

public long getLong(java.lang.String key,
                    long defaultValue)
             throws StringValueConversionException
Description copied from interface: IValueMap
Retrieves a long value by key, using a default value if not found.

Specified by:
getLong in interface IValueMap
Parameters:
key - the key
defaultValue - value to use if no value in this IValueMap
Returns:
the value
Throws:
StringValueConversionException
See Also:
IValueMap.getLong(String, long)

getLong

public long getLong(java.lang.String key)
             throws StringValueConversionException
Description copied from interface: IValueMap
Retrieves a long value by key.

Specified by:
getLong in interface IValueMap
Parameters:
key - the key
Returns:
the value
Throws:
StringValueConversionException
See Also:
IValueMap.getLong(String)

getString

public java.lang.String getString(java.lang.String key,
                                  java.lang.String defaultValue)
Description copied from interface: IValueMap
Retrieves a String by key, using a default value if not found.

Specified by:
getString in interface IValueMap
Parameters:
key - the key
defaultValue - default value to return if value is null
Returns:
the String
See Also:
IValueMap.getString(String, String)

getString

public java.lang.String getString(java.lang.String key)
Description copied from interface: IValueMap
Retrieves a String by key.

Specified by:
getString in interface IValueMap
Parameters:
key - the key
Returns:
the String
See Also:
IValueMap.getString(String)

getStringArray

public java.lang.String[] getStringArray(java.lang.String key)
Description copied from interface: IValueMap
Retrieves a 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.

Specified by:
getStringArray in interface IValueMap
Parameters:
key - the key
Returns:
the String array of that key
See Also:
IValueMap.getStringArray(String)

getStringValue

public StringValue getStringValue(java.lang.String key)
Description copied from interface: IValueMap
Retrieves a StringValue object by key.

Specified by:
getStringValue in interface IValueMap
Parameters:
key - the key
Returns:
the StringValue object
See Also:
IValueMap.getStringValue(String)

getTime

public Time getTime(java.lang.String key)
             throws StringValueConversionException
Description copied from interface: IValueMap
Retrieves a Time object by key.

Specified by:
getTime in interface IValueMap
Parameters:
key - the key
Returns:
the Time object
Throws:
StringValueConversionException
See Also:
IValueMap.getTime(String)

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface java.util.Map<java.lang.String,java.lang.Object>
See Also:
Map.isEmpty()

isImmutable

public boolean isImmutable()
Description copied from interface: IValueMap
Returns whether or not this IValueMap is immutable.

Specified by:
isImmutable in interface IValueMap
Returns:
whether or not this IValueMap is immutable
See Also:
IValueMap.isImmutable()

keySet

public java.util.Set<java.lang.String> keySet()
Specified by:
keySet in interface java.util.Map<java.lang.String,java.lang.Object>
See Also:
Map.keySet()

makeImmutable

public IValueMap makeImmutable()
Description copied from interface: IValueMap
Makes this 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.

Specified by:
makeImmutable in interface IValueMap
Returns:
this IValueMap
See Also:
IValueMap.makeImmutable()

put

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

putAll

public void putAll(java.util.Map<? extends java.lang.String,?> map)
Specified by:
putAll in interface java.util.Map<java.lang.String,java.lang.Object>
See Also:
Map.putAll(Map)

remove

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

size

public int size()
Specified by:
size in interface java.util.Map<java.lang.String,java.lang.Object>
See Also:
Map.size()

values

public java.util.Collection<java.lang.Object> values()
Specified by:
values in interface java.util.Map<java.lang.String,java.lang.Object>
See Also:
Map.values()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
IValueMap#toString()

getAsBoolean

public java.lang.Boolean getAsBoolean(java.lang.String key)
Description copied from interface: IValueMap
Retrieves a Boolean value by key.

Specified by:
getAsBoolean in interface IValueMap
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: IValueMap
Retrieves a boolean value by key.

Specified by:
getAsBoolean in interface IValueMap
Parameters:
key - the key
defaultValue - 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: IValueMap
Retrieves an Integer value by key.

Specified by:
getAsInteger in interface IValueMap
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: IValueMap
Retrieves an integer value by key.

Specified by:
getAsInteger in interface IValueMap
Parameters:
key - the key
defaultValue - 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: IValueMap
Retrieves a Long value by key.

Specified by:
getAsLong in interface IValueMap
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: IValueMap
Retrieves a long value by key.

Specified by:
getAsLong in interface IValueMap
Parameters:
key - the key
defaultValue - 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: IValueMap
Retrieves a Double value by key.

Specified by:
getAsDouble in interface IValueMap
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: IValueMap
Retrieves a double value by key.

Specified by:
getAsDouble in interface IValueMap
Parameters:
key - the key
defaultValue - 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: IValueMap
Retrieves a Duration value by key.

Specified by:
getAsDuration in interface IValueMap
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: IValueMap
Retrieves a Duration value by key.

Specified by:
getAsDuration in interface IValueMap
Parameters:
key - the key
defaultValue - 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: IValueMap
Retrieves a Time value by key.

Specified by:
getAsTime in interface IValueMap
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: IValueMap
Retrieves a Time value by key.

Specified by:
getAsTime in interface IValueMap
Parameters:
key - the key
defaultValue - 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: IValueMap
Retrieves an Enum value by key.

Specified by:
getAsEnum in interface IValueMap
Type Parameters:
T - type of enum
Parameters:
key - the key
eClass - 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(String, Class)

getAsEnum

public <T extends java.lang.Enum<T>> T getAsEnum(java.lang.String key,
                                                 T defaultValue)
Description copied from interface: IValueMap
Retrieves an Enum value by key.

Specified by:
getAsEnum in interface IValueMap
Type Parameters:
T - type of enum
Parameters:
key - the key
defaultValue - 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.Class)

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: IValueMap
Retrieves an Enum value by key.

Specified by:
getAsEnum in interface IValueMap
Type Parameters:
T - type of enum
Parameters:
key - the key
eClass - the enumeration class
defaultValue - 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(String, Class, Enum)


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.