40 |
|
* |
41 |
|
* <p>This interface is a member of the |
42 |
|
* <a href="{@docRoot}/../technotes/guides/collections/index.html"> |
43 |
< |
* Java Caollections Framework</a>. |
43 |
> |
* Java Collections Framework</a>. |
44 |
|
* |
45 |
|
* @since 1.5 |
46 |
|
* @author Doug Lea |
47 |
|
* @param <K> the type of keys maintained by this map |
48 |
|
* @param <V> the type of mapped values |
49 |
|
*/ |
50 |
< |
public interface ConcurrentMap<K, V> extends Map<K, V> { |
50 |
> |
public interface ConcurrentMap<K,V> extends Map<K,V> { |
51 |
|
|
52 |
|
/** |
53 |
|
* {@inheritDoc} |
72 |
|
* @implSpec The default implementation is equivalent to, for this |
73 |
|
* {@code map}: |
74 |
|
* <pre> {@code |
75 |
< |
* for ((Map.Entry<K, V> entry : map.entrySet()) |
75 |
> |
* for ((Map.Entry<K,V> entry : map.entrySet()) |
76 |
|
* action.accept(entry.getKey(), entry.getValue()); |
77 |
|
* }</pre> |
78 |
|
* |
87 |
|
@Override |
88 |
|
default void forEach(BiConsumer<? super K, ? super V> action) { |
89 |
|
Objects.requireNonNull(action); |
90 |
< |
for (Map.Entry<K, V> entry : entrySet()) { |
90 |
> |
for (Map.Entry<K,V> entry : entrySet()) { |
91 |
|
K k; |
92 |
|
V v; |
93 |
|
try { |
94 |
|
k = entry.getKey(); |
95 |
|
v = entry.getValue(); |
96 |
< |
} catch(IllegalStateException ise) { |
96 |
> |
} catch (IllegalStateException ise) { |
97 |
|
// this usually means the entry is no longer in the map. |
98 |
|
continue; |
99 |
|
} |
132 |
|
* @throws IllegalArgumentException if some property of the specified key |
133 |
|
* or value prevents it from being stored in this map |
134 |
|
*/ |
135 |
< |
V putIfAbsent(K key, V value); |
135 |
> |
V putIfAbsent(K key, V value); |
136 |
|
|
137 |
|
/** |
138 |
|
* Removes the entry for a key only if currently mapped to a given value. |
231 |
|
* @implSpec |
232 |
|
* <p>The default implementation is equivalent to, for this {@code map}: |
233 |
|
* <pre> {@code |
234 |
< |
* for ((Map.Entry<K, V> entry : map.entrySet()) |
234 |
> |
* for ((Map.Entry<K,V> entry : map.entrySet()) |
235 |
|
* do { |
236 |
|
* K k = entry.getKey(); |
237 |
|
* V v = entry.getValue(); |
238 |
< |
* } while(!replace(k, v, function.apply(k, v))); |
238 |
> |
* } while (!replace(k, v, function.apply(k, v))); |
239 |
|
* }</pre> |
240 |
|
* |
241 |
|
* The default implementation may retry these steps when multiple |
252 |
|
default void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) { |
253 |
|
Objects.requireNonNull(function); |
254 |
|
forEach((k,v) -> { |
255 |
< |
while(!replace(k, v, function.apply(k, v))) { |
255 |
> |
while (!replace(k, v, function.apply(k, v))) { |
256 |
|
// v changed or k is gone |
257 |
|
if ( (v = get(k)) == null) { |
258 |
|
// k is no longer in the map. |
330 |
|
BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
331 |
|
Objects.requireNonNull(remappingFunction); |
332 |
|
V oldValue; |
333 |
< |
while((oldValue = get(key)) != null) { |
333 |
> |
while ((oldValue = get(key)) != null) { |
334 |
|
V newValue = remappingFunction.apply(key, oldValue); |
335 |
|
if (newValue != null) { |
336 |
|
if (replace(key, oldValue, newValue)) |
379 |
|
BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
380 |
|
Objects.requireNonNull(remappingFunction); |
381 |
|
V oldValue = get(key); |
382 |
< |
for(;;) { |
382 |
> |
for (;;) { |
383 |
|
V newValue = remappingFunction.apply(key, oldValue); |
384 |
|
if (newValue == null) { |
385 |
|
// delete mapping |