Class ValueProtectingMap<K extends Serializable,​V extends Serializable>

  • Type Parameters:
    K - the map key type (must extend Serializable)
    V - the map value type (must extend Serializable)
    All Implemented Interfaces:
    Serializable, Map<K,​V>

    public class ValueProtectingMap<K extends Serializable,​V extends Serializable>
    extends Object
    implements Map<K,​V>, Serializable
    A map that protects keys and values from accidental modification.

    Use this map when keys or values need to be protected against client modification. For example, when a component pulls a map from a common resource it can wrap the map with this class to prevent any accidental modification of the shared resource.

    Upon first write to this map , the underlying map will be copied (selectively cloned), the original map handle will be discarded and the copied map will be used. Note that the map copy process will also occur if any mutable value is in danger of being exposed to client modification. Therefore, methods that iterate and retrieve values will also trigger the copy if any values are mutable.

    Since:
    3.4.9, 4.0.1
    Author:
    Derek Hulley
    See Also:
    Serialized Form
    • Field Detail

      • DEFAULT_IMMUTABLE_CLASSES

        public static final Set<Class<?>> DEFAULT_IMMUTABLE_CLASSES
        Default immutable classes:
      • String
      • BigDecimal
      • BigInteger
      • Byte
      • Double
      • Float
      • Integer
      • Long
      • Short
      • Boolean
      • Date
      • Locale
  • Constructor Detail

    • ValueProtectingMap

      public ValueProtectingMap​(Map<K,​V> protectedMap)
      Construct providing a protected map and using only the default immutable classes
      Parameters:
      protectedMap - the map to safeguard
    • ValueProtectingMap

      public ValueProtectingMap​(Map<K,​V> protectedMap,
                                Set<Class<?>> immutableClasses)
      Construct providing a protected map, complementing the set of default immutable classes
      Parameters:
      protectedMap - the map to safeguard
      immutableClasses - additional immutable classes over and above the default set (may be null