@Override public V get(Object key) { readLock.lock(); try { V value = map.get(key); return ValueProtectingMap.protectValue(value, immutableClasses); } finally { readLock.unlock(); } }
@Override public V get(Object key) { readLock.lock(); try { V value = map.get(key); return ValueProtectingMap.protectValue(value, immutableClasses); } finally { readLock.unlock(); } }
/** * Utility method to clone a map, preserving immutable instances * * @param <K> the map key type, which must be {@link Serializable} * @param <V> the map value type, which must be {@link Serializable} * @param map the map to copy * @param immutableClasses a set of classes that can be considered immutable * over and above the {@link #DEFAULT_IMMUTABLE_CLASSES default set} */ public static <K extends Serializable, V extends Serializable> Map<K, V> cloneMap(Map<K, V> map, Set<Class<?>> immutableClasses) { Map<K, V> copy = new HashMap<K, V>((int)(map.size() * 1.3)); for (Map.Entry<K, V> element : map.entrySet()) { K key = element.getKey(); V value = element.getValue(); // Clone as necessary key = ValueProtectingMap.protectValue(key, immutableClasses); value = ValueProtectingMap.protectValue(value, immutableClasses); copy.put(key, value); } return copy; }
/** * Utility method to clone a map, preserving immutable instances * * @param <K> the map key type, which must be {@link Serializable} * @param <V> the map value type, which must be {@link Serializable} * @param map the map to copy * @param immutableClasses a set of classes that can be considered immutable * over and above the {@link #DEFAULT_IMMUTABLE_CLASSES default set} */ public static <K extends Serializable, V extends Serializable> Map<K, V> cloneMap(Map<K, V> map, Set<Class<?>> immutableClasses) { Map<K, V> copy = new HashMap<K, V>((int)(map.size() * 1.3)); for (Map.Entry<K, V> element : map.entrySet()) { K key = element.getKey(); V value = element.getValue(); // Clone as necessary key = ValueProtectingMap.protectValue(key, immutableClasses); value = ValueProtectingMap.protectValue(value, immutableClasses); copy.put(key, value); } return copy; }