V v = segment.get(key, hash); return v == null ? segment.put(key, hash, null, mappingFunction, true) : v;
V v = segment.get(key, hash); return v == null ? segment.put(key, hash, null, mappingFunction, true) : v;
V applyIfPresent(K key, int hash, IBiFunction<? super K, ? super V, ? extends V> remappingFunction) { lock(); try { V oldValue = get(key, hash); if (oldValue == null) { return null; } V newValue = remappingFunction.apply(key, oldValue); if (newValue == null) { removeInternal(key, hash, oldValue, false); return null; } else { putInternal(key, hash, newValue, null, false); return newValue; } } finally { unlock(); } }
V applyIfPresent(K key, int hash, IBiFunction<? super K, ? super V, ? extends V> remappingFunction) { lock(); try { V oldValue = get(key, hash); if (oldValue == null) { return null; } V newValue = remappingFunction.apply(key, oldValue); if (newValue == null) { removeInternal(key, hash, oldValue, false); return null; } else { putInternal(key, hash, newValue, null, false); return newValue; } } finally { unlock(); } }
/** * Returns the value to which the specified key is mapped, * or {@code null} if this map contains no mapping for the key. * <p> * <p>If this map contains a mapping from a key * {@code k} to a value {@code v} such that {@code key.equals(k)}, * then this method returns {@code v}; otherwise it returns * {@code null}. (There can be at most one such mapping.) * * @throws NullPointerException if the specified key is null */ public V get(Object key) { int hash = hashOf(key); return segmentFor(hash).get(key, hash); }
V merge(K key, V value, int hash, IBiFunction<? super V, ? super V, ? extends V> remappingFunction) { lock(); try { V oldValue = get(key, hash); V newValue = (oldValue == null) ? value : remappingFunction.apply(oldValue, value); if (newValue == null) { removeInternal(key, hash, oldValue, false); return null; } else { putInternal(key, hash, newValue, null, false); return newValue; } } finally { unlock(); } }
/** * Returns the value to which the specified key is mapped, * or {@code null} if this map contains no mapping for the key. * <p> * <p>If this map contains a mapping from a key * {@code k} to a value {@code v} such that {@code key.equals(k)}, * then this method returns {@code v}; otherwise it returns * {@code null}. (There can be at most one such mapping.) * * @throws NullPointerException if the specified key is null */ public V get(Object key) { int hash = hashOf(key); return segmentFor(hash).get(key, hash); }
V merge(K key, V value, int hash, IBiFunction<? super V, ? super V, ? extends V> remappingFunction) { lock(); try { V oldValue = get(key, hash); V newValue = (oldValue == null) ? value : remappingFunction.apply(oldValue, value); if (newValue == null) { removeInternal(key, hash, oldValue, false); return null; } else { putInternal(key, hash, newValue, null, false); return newValue; } } finally { unlock(); } }
@Override public V applyIfPresent(K key, IBiFunction<? super K, ? super V, ? extends V> remappingFunction) { checkNotNull(key); checkNotNull(remappingFunction); int hash = hashOf(key); Segment<K, V> segment = segmentFor(hash); V v = segment.get(key, hash); if (v == null) { return null; } return segmentFor(hash).applyIfPresent(key, hash, remappingFunction); }
@Override public V applyIfPresent(K key, IBiFunction<? super K, ? super V, ? extends V> remappingFunction) { checkNotNull(key); checkNotNull(remappingFunction); int hash = hashOf(key); Segment<K, V> segment = segmentFor(hash); V v = segment.get(key, hash); if (v == null) { return null; } return segmentFor(hash).applyIfPresent(key, hash, remappingFunction); }