40 |
|
* @param <K> the type of keys maintained by this map |
41 |
|
* @param <V> the type of mapped values |
42 |
|
*/ |
43 |
< |
public interface ConcurrentMap<K, V> extends Map<K, V> { |
43 |
> |
public interface ConcurrentMap<K,V> extends Map<K,V> { |
44 |
|
|
45 |
|
/** |
46 |
|
* {@inheritDoc} |
66 |
|
* @implSpec The default implementation is equivalent to, for this |
67 |
|
* {@code map}: |
68 |
|
* <pre> {@code |
69 |
< |
* for ((Map.Entry<K, V> entry : map.entrySet()) |
70 |
< |
* action.accept(entry.getKey(), entry.getValue()); |
69 |
> |
* for (Map.Entry<K,V> entry : map.entrySet()) |
70 |
> |
* action.accept(entry.getKey(), entry.getValue()); |
71 |
|
* }</pre> |
72 |
|
* |
73 |
|
* @implNote The default implementation assumes that |
81 |
|
@Override |
82 |
|
default void forEach(BiConsumer<? super K, ? super V> action) { |
83 |
|
Objects.requireNonNull(action); |
84 |
< |
for (Map.Entry<K, V> entry : entrySet()) { |
84 |
> |
for (Map.Entry<K,V> entry : entrySet()) { |
85 |
|
K k; |
86 |
|
V v; |
87 |
|
try { |
88 |
|
k = entry.getKey(); |
89 |
|
v = entry.getValue(); |
90 |
< |
} catch(IllegalStateException ise) { |
90 |
> |
} catch (IllegalStateException ise) { |
91 |
|
// this usually means the entry is no longer in the map. |
92 |
|
continue; |
93 |
|
} |
229 |
|
* @implSpec |
230 |
|
* <p>The default implementation is equivalent to, for this {@code map}: |
231 |
|
* <pre> {@code |
232 |
< |
* for ((Map.Entry<K, V> entry : map.entrySet()) |
233 |
< |
* do { |
234 |
< |
* K k = entry.getKey(); |
235 |
< |
* V v = entry.getValue(); |
236 |
< |
* } while(!replace(k, v, function.apply(k, v))); |
232 |
> |
* for (Map.Entry<K,V> entry : map.entrySet()) |
233 |
> |
* do { |
234 |
> |
* K k = entry.getKey(); |
235 |
> |
* V v = entry.getValue(); |
236 |
> |
* } while (!replace(k, v, function.apply(k, v))); |
237 |
|
* }</pre> |
238 |
|
* |
239 |
|
* The default implementation may retry these steps when multiple |
255 |
|
default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) { |
256 |
|
Objects.requireNonNull(function); |
257 |
|
forEach((k,v) -> { |
258 |
< |
while(!replace(k, v, function.apply(k, v))) { |
258 |
> |
while (!replace(k, v, function.apply(k, v))) { |
259 |
|
// v changed or k is gone |
260 |
|
if ( (v = get(k)) == null) { |
261 |
|
// k is no longer in the map. |
343 |
|
BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
344 |
|
Objects.requireNonNull(remappingFunction); |
345 |
|
V oldValue; |
346 |
< |
while((oldValue = get(key)) != null) { |
346 |
> |
while ((oldValue = get(key)) != null) { |
347 |
|
V newValue = remappingFunction.apply(key, oldValue); |
348 |
|
if (newValue != null) { |
349 |
|
if (replace(key, oldValue, newValue)) |
397 |
|
BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
398 |
|
Objects.requireNonNull(remappingFunction); |
399 |
|
V oldValue = get(key); |
400 |
< |
for(;;) { |
400 |
> |
for (;;) { |
401 |
|
V newValue = remappingFunction.apply(key, oldValue); |
402 |
|
if (newValue == null) { |
403 |
|
// delete mapping |