@Test public void testPutIfAbsent() { final CopyOnWriteMap<String, String> map = new CopyOnWriteMap<>(); map.putIfAbsent("a", "b"); map.putIfAbsent("a", "c"); assertEquals("b", map.get("a")); }
@Override public synchronized V putIfAbsent(final K key, final V value) { final Map<K, V> oldDelegate = this.delegate; final V existing = oldDelegate.get(key); if (existing != null) { return existing; } putInternal(key, value); return null; }
CopyOnWriteMap implements ConcurrentMap<K, V> { @Override public synchronized V putIfAbsent(final K key, final V value) { final Map<K, V> oldDelegate = this.delegate; final V existing = oldDelegate.get(key); if (existing != null) { return existing; } putInternal(key, value); return null; } }
CopyOnWriteMap implements ConcurrentMap<K, V> { @Override public synchronized V putIfAbsent(final K key, final V value) { final Map<K, V> oldDelegate = this.delegate; final V existing = oldDelegate.get(key); if (existing != null) { return existing; } putInternal(key, value); return null; } CopyOnWriteMap();  CopyOnWriteMap(final Map<K, V> existing); }
CopyOnWriteMap implements ConcurrentMap<K, V> { @Override public synchronized V putIfAbsent(final K key, final V value) { final Map<K, V> oldDelegate = this.delegate; final V existing = oldDelegate.get(key); if (existing != null) { return existing; } putInternal(key, value); return null; } CopyOnWriteMap();  CopyOnWriteMap(final Map<K, V> existing); @Override synchronized V putIfAbsent(final K key, final V value); @Override synchronized boolean remove(final Object key, final Object value); @Override synchronized boolean replace(final K key, final V oldValue, final V newValue); @Override synchronized V replace(final K key, final V value); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(final Object key); @Override boolean containsValue(final Object value); @Override V get(final Object key); @Override synchronized V put(final K key, final V value); @Override synchronized V remove(final Object key); @Override synchronized void putAll(final Map<? extends K, ? extends V> m); @Override synchronized void clear(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); V removeInternal(final Object key); }
CopyOnWriteMap implements ConcurrentMap<K, V> { @Override public synchronized V putIfAbsent(final K key, final V value) { final Map<K, V> oldDelegate = this.delegate; final V existing = oldDelegate.get(key); if (existing != null) { return existing; } putInternal(key, value); return null; } CopyOnWriteMap();  CopyOnWriteMap(final Map<K, V> existing); @Override synchronized V putIfAbsent(final K key, final V value); @Override synchronized boolean remove(final Object key, final Object value); @Override synchronized boolean replace(final K key, final V oldValue, final V newValue); @Override synchronized V replace(final K key, final V value); @Override int size(); @Override boolean isEmpty(); @Override boolean containsKey(final Object key); @Override boolean containsValue(final Object value); @Override V get(final Object key); @Override synchronized V put(final K key, final V value); @Override synchronized V remove(final Object key); @Override synchronized void putAll(final Map<? extends K, ? extends V> m); @Override synchronized void clear(); @Override Set<K> keySet(); @Override Collection<V> values(); @Override Set<Entry<K, V>> entrySet(); V removeInternal(final Object key);  }