K
- the map key type (must extend Serializable
)V
- the map value type (must extend Serializable
)public class ValueProtectingMap<K extends Serializable,V extends Serializable> extends Object implements Map<K,V>, Serializable
Modifier and Type | Field and Description |
---|---|
static Set<Class<?>> |
DEFAULT_IMMUTABLE_CLASSES
Default immutable classes:
String
BigDecimal
BigInteger
Byte
Double
Float
Integer
Long
Short
Boolean
Date
Locale
|
Constructor and Description |
---|
ValueProtectingMap(Map<K,V> protectedMap)
Construct providing a protected map and using only the
default immutable classes |
ValueProtectingMap(Map<K,V> protectedMap,
Set<Class<?>> immutableClasses)
Construct providing a protected map, complementing the set of
default immutable classes |
Modifier and Type | Method and Description |
---|---|
void |
clear() |
static <K extends Serializable,V extends Serializable> |
cloneMap(Map<K,V> map,
Set<Class<?>> immutableClasses)
Utility method to clone a map, preserving immutable instances
|
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<K,V>> |
entrySet() |
boolean |
equals(Object obj) |
V |
get(Object key) |
int |
hashCode() |
boolean |
isEmpty() |
Set<K> |
keySet() |
static <S extends Serializable> |
mustProtectValue(S value,
Set<Class<?>> immutableClasses)
Utility method to check if values need to be cloned or not
|
static <S extends Serializable> |
protectValue(S value,
Set<Class<?>> immutableClasses)
Protect a specific value if it is considered mutable
|
V |
put(K key,
V value) |
void |
putAll(Map<? extends K,? extends V> m) |
V |
remove(Object key) |
int |
size() |
String |
toString() |
Collection<V> |
values() |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public ValueProtectingMap(Map<K,V> protectedMap)
default immutable classes
protectedMap
- the map to safeguardpublic ValueProtectingMap(Map<K,V> protectedMap, Set<Class<?>> immutableClasses)
default immutable classes
protectedMap
- the map to safeguardimmutableClasses
- additional immutable classes
over and above the default set
(may be nullpublic static <S extends Serializable> S protectValue(S value, Set<Class<?>> immutableClasses)
S
- the type of the value, which must be Serializable
value
- the value to protect if it is mutable (may be null)immutableClasses
- a set of classes that can be considered immutable
over and above the default set
public static <S extends Serializable> boolean mustProtectValue(S value, Set<Class<?>> immutableClasses)
S
- the type of the value, which must be Serializable
value
- the value to checkimmutableClasses
- a set of classes that can be considered immutable
over and above the default set
public static <K extends Serializable,V extends Serializable> Map<K,V> cloneMap(Map<K,V> map, Set<Class<?>> immutableClasses)
K
- the map key type, which must be Serializable
V
- the map value type, which must be Serializable
map
- the map to copyimmutableClasses
- a set of classes that can be considered immutable
over and above the default set
public int size()
size
in interface Map<K extends Serializable,V extends Serializable>
public boolean isEmpty()
isEmpty
in interface Map<K extends Serializable,V extends Serializable>
public boolean containsKey(Object key)
containsKey
in interface Map<K extends Serializable,V extends Serializable>
public boolean containsValue(Object value)
containsValue
in interface Map<K extends Serializable,V extends Serializable>
public int hashCode()
hashCode
in interface Map<K extends Serializable,V extends Serializable>
hashCode
in class Object
public boolean equals(Object obj)
equals
in interface Map<K extends Serializable,V extends Serializable>
equals
in class Object
public V get(Object key)
get
in interface Map<K extends Serializable,V extends Serializable>
public V put(K key, V value)
put
in interface Map<K extends Serializable,V extends Serializable>
public V remove(Object key)
remove
in interface Map<K extends Serializable,V extends Serializable>
public void putAll(Map<? extends K,? extends V> m)
putAll
in interface Map<K extends Serializable,V extends Serializable>
public void clear()
clear
in interface Map<K extends Serializable,V extends Serializable>
public Set<K> keySet()
keySet
in interface Map<K extends Serializable,V extends Serializable>
public Collection<V> values()
values
in interface Map<K extends Serializable,V extends Serializable>
public Set<Map.Entry<K,V>> entrySet()
entrySet
in interface Map<K extends Serializable,V extends Serializable>
Copyright © 2005–2017 Alfresco Software. All rights reserved.