Code example for ImmutableMap.Builder

Methods: build

0
 */ 
public class COWMap<K, V>  extends ForwardingMap<K, V> implements Map<K, V> {
    private final AtomicReference<ImmutableMap<K, V>> m_map;
 
    public COWMap() { 
        m_map = new AtomicReference<ImmutableMap<K, V>>(new Builder<K, V>().build());
    } 
 
    public COWMap(Map<K, V> map) {
        if (map == null) {
            throw new IllegalArgumentException("Wrapped map cannot be null");
        } 
        m_map = new AtomicReference<ImmutableMap<K, V>>(new Builder<K, V>().putAll(map).build());
    } 
 
    @Override 
    public V put(K key, V value) {
        while (true) { 
            ImmutableMap<K, V> original = m_map.get();
            Builder<K, V> builder = new Builder<K, V>();