Package org.apache.wicket.util.value
Class CopyOnWriteValueMap
- java.lang.Object
-
- org.apache.wicket.util.value.CopyOnWriteValueMap
-
- All Implemented Interfaces:
Serializable
,Map<String,Object>
,IValueMap
public class CopyOnWriteValueMap extends Object implements IValueMap, Serializable
An implementation ofIValueMap
that makes a copy when a caller tries to change an immutableMap
. That is, theMap
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
-
-
Constructor Summary
Constructors Constructor Description CopyOnWriteValueMap(IValueMap wrapped)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
boolean
containsKey(Object key)
boolean
containsValue(Object value)
Set<Map.Entry<String,Object>>
entrySet()
boolean
equals(Object o)
Object
get(Object key)
Boolean
getAsBoolean(String key)
Retrieves aBoolean
value by key.boolean
getAsBoolean(String key, boolean defaultValue)
Retrieves aboolean
value by key.Double
getAsDouble(String key)
Retrieves aDouble
value by key.double
getAsDouble(String key, double defaultValue)
Retrieves adouble
value by key.Duration
getAsDuration(String key)
Retrieves aDuration
value by key.Duration
getAsDuration(String key, Duration defaultValue)
Retrieves aDuration
value by key.<T extends Enum<T>>
TgetAsEnum(String key, Class<T> eClass)
Retrieves anEnum
value by key.<T extends Enum<T>>
TgetAsEnum(String key, Class<T> eClass, T defaultValue)
Retrieves anEnum
value by key.<T extends Enum<T>>
TgetAsEnum(String key, T defaultValue)
Retrieves anEnum
value by key.Instant
getAsInstant(String key)
Retrieves aTime
value by key.Integer
getAsInteger(String key)
Retrieves anInteger
value by key.int
getAsInteger(String key, int defaultValue)
Retrieves aninteger
value by key.Long
getAsLong(String key)
Retrieves aLong
value by key.long
getAsLong(String key, long defaultValue)
Retrieves along
value by key.Instant
getAsTime(String key, Instant defaultValue)
Retrieves aTime
value by key.boolean
getBoolean(String key)
Retrieves aboolean
value by key.CharSequence
getCharSequence(String key)
Retrieves aCharSequence
by key.double
getDouble(String key)
Retrieves adouble
value by key.double
getDouble(String key, double defaultValue)
Retrieves adouble
value by key, using a default value if not found.Duration
getDuration(String key)
Retrieves aDuration
by key.Instant
getInstant(String key)
Retrieves aInstant
object by key.int
getInt(String key)
Retrieves anint
value by key.int
getInt(String key, int defaultValue)
Retrieves anint
value by key, using a default value if not found.String
getKey(String key)
Provided that the hash key is aString
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 along
value by key.long
getLong(String key, long defaultValue)
Retrieves along
value by key, using a default value if not found.String
getString(String key)
Retrieves aString
by key.String
getString(String key, String defaultValue)
Retrieves aString
by key, using a default value if not found.String[]
getStringArray(String key)
Retrieves aString
array by key.StringValue
getStringValue(String key)
Retrieves aStringValue
object by key.int
hashCode()
boolean
isEmpty()
boolean
isImmutable()
Returns whether or not thisIValueMap
is immutable.Set<String>
keySet()
IValueMap
makeImmutable()
Makes thisIValueMap
immutable by changing the underlying map representation to aCollections.unmodifiableMap
.Object
put(String key, Object value)
void
putAll(Map<? extends String,?> map)
Object
remove(Object key)
int
size()
Collection<Object>
values()
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
-
-
-
Constructor Detail
-
CopyOnWriteValueMap
public CopyOnWriteValueMap(IValueMap wrapped)
Constructor.- Parameters:
wrapped
- the wrappedIValueMap
-
-
Method Detail
-
containsKey
public boolean containsKey(Object key)
- Specified by:
containsKey
in interfaceMap<String,Object>
-
containsValue
public boolean containsValue(Object value)
- Specified by:
containsValue
in interfaceMap<String,Object>
-
hashCode
public int hashCode()
-
getBoolean
public boolean getBoolean(String key) throws StringValueConversionException
Description copied from interface:IValueMap
Retrieves aboolean
value by key.- Specified by:
getBoolean
in interfaceIValueMap
- Parameters:
key
- the key- Returns:
- the value
- Throws:
StringValueConversionException
-
getCharSequence
public CharSequence getCharSequence(String key)
Description copied from interface:IValueMap
Retrieves aCharSequence
by key.- Specified by:
getCharSequence
in interfaceIValueMap
- Parameters:
key
- the key- Returns:
- the
CharSequence
-
getDouble
public double getDouble(String key) throws StringValueConversionException
Description copied from interface:IValueMap
Retrieves adouble
value by key.- Specified by:
getDouble
in interfaceIValueMap
- Parameters:
key
- the key- Returns:
- the value
- Throws:
StringValueConversionException
-
getDouble
public double getDouble(String key, double defaultValue)
Description copied from interface:IValueMap
Retrieves adouble
value by key, using a default value if not found.
-
getDuration
public Duration getDuration(String key) throws StringValueConversionException
Description copied from interface:IValueMap
Retrieves aDuration
by key.- Specified by:
getDuration
in interfaceIValueMap
- Parameters:
key
- the key- Returns:
- the
Duration
value - Throws:
StringValueConversionException
-
getInt
public int getInt(String key, int defaultValue)
Description copied from interface:IValueMap
Retrieves anint
value by key, using a default value if not found.
-
getInt
public int getInt(String key) throws StringValueConversionException
Description copied from interface:IValueMap
Retrieves anint
value by key.- Specified by:
getInt
in interfaceIValueMap
- Parameters:
key
- the key- Returns:
- the value
- Throws:
StringValueConversionException
-
getKey
public String getKey(String key)
Description copied from interface:IValueMap
Provided that the hash key is aString
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.
-
getLong
public long getLong(String key, long defaultValue)
Description copied from interface:IValueMap
Retrieves along
value by key, using a default value if not found.
-
getLong
public long getLong(String key) throws StringValueConversionException
Description copied from interface:IValueMap
Retrieves along
value by key.- Specified by:
getLong
in interfaceIValueMap
- Parameters:
key
- the key- Returns:
- the value
- Throws:
StringValueConversionException
-
getString
public String getString(String key, String defaultValue)
Description copied from interface:IValueMap
Retrieves aString
by key, using a default value if not found.
-
getString
public String getString(String key)
Description copied from interface:IValueMap
Retrieves aString
by key.
-
getStringArray
public String[] getStringArray(String key)
Description copied from interface:IValueMap
Retrieves aString
array by key. If the value was aString[]
it will be returned directly. If it was aString
it will be converted to aString
array of length one. If it was an array of another type, aString
array will be made and each element will be converted to aString
.- Specified by:
getStringArray
in interfaceIValueMap
- Parameters:
key
- the key- Returns:
- the
String
array of that key
-
getStringValue
public StringValue getStringValue(String key)
Description copied from interface:IValueMap
Retrieves aStringValue
object by key.- Specified by:
getStringValue
in interfaceIValueMap
- Parameters:
key
- the key- Returns:
- the
StringValue
object
-
getInstant
public Instant getInstant(String key) throws StringValueConversionException
Description copied from interface:IValueMap
Retrieves aInstant
object by key.- Specified by:
getInstant
in interfaceIValueMap
- Parameters:
key
- the key- Returns:
- the
Instant
object - Throws:
StringValueConversionException
-
isImmutable
public boolean isImmutable()
Description copied from interface:IValueMap
Returns whether or not thisIValueMap
is immutable.- Specified by:
isImmutable
in interfaceIValueMap
- Returns:
- whether or not this
IValueMap
is immutable
-
makeImmutable
public IValueMap makeImmutable()
Description copied from interface:IValueMap
Makes thisIValueMap
immutable by changing the underlying map representation to aCollections.unmodifiableMap
. After calling this method, any attempt to modify thisIValueMap
will result in aRuntimeException
being thrown by theCollections
framework.- Specified by:
makeImmutable
in interfaceIValueMap
- Returns:
- this
IValueMap
-
getAsBoolean
public Boolean getAsBoolean(String key)
Description copied from interface:IValueMap
Retrieves aBoolean
value by key.- Specified by:
getAsBoolean
in 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:IValueMap
Retrieves aboolean
value by key.- Specified by:
getAsBoolean
in 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:IValueMap
Retrieves anInteger
value by key.- Specified by:
getAsInteger
in 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:IValueMap
Retrieves aninteger
value by key.- Specified by:
getAsInteger
in 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:IValueMap
Retrieves aLong
value by key.
-
getAsLong
public long getAsLong(String key, long defaultValue)
Description copied from interface:IValueMap
Retrieves along
value by key.
-
getAsDouble
public Double getAsDouble(String key)
Description copied from interface:IValueMap
Retrieves aDouble
value by key.- Specified by:
getAsDouble
in 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:IValueMap
Retrieves adouble
value by key.- Specified by:
getAsDouble
in 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:IValueMap
Retrieves aDuration
value by key.- Specified by:
getAsDuration
in 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:IValueMap
Retrieves aDuration
value by key.- Specified by:
getAsDuration
in 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:IValueMap
Retrieves aTime
value by key.- Specified by:
getAsInstant
in 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:IValueMap
Retrieves aTime
value by key.
-
getAsEnum
public <T extends Enum<T>> T getAsEnum(String key, Class<T> eClass)
Description copied from interface:IValueMap
Retrieves anEnum
value by key.
-
getAsEnum
public <T extends Enum<T>> T getAsEnum(String key, T defaultValue)
Description copied from interface:IValueMap
Retrieves anEnum
value by key.
-
getAsEnum
public <T extends Enum<T>> T getAsEnum(String key, Class<T> eClass, T defaultValue)
Description copied from interface:IValueMap
Retrieves anEnum
value by key.- Specified by:
getAsEnum
in 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
-
-