Committed by
Gerrit Code Review
Refactor: Use putIfAbsent() to show the intention more clearly
Change-Id: I2fad1709cc6f8827d382a07b55cd89d2814ede36
Showing
1 changed file
with
1 additions
and
2 deletions
... | @@ -292,9 +292,8 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour | ... | @@ -292,9 +292,8 @@ public class ConsistentResourceStore extends AbstractStore<ResourceEvent, Resour |
292 | * @return true if the operation succeeds, false otherwise. | 292 | * @return true if the operation succeeds, false otherwise. |
293 | */ | 293 | */ |
294 | private <K, V> boolean appendValues(TransactionalMap<K, List<V>> map, K key, List<V> values) { | 294 | private <K, V> boolean appendValues(TransactionalMap<K, List<V>> map, K key, List<V> values) { |
295 | - List<V> oldValues = map.get(key); | 295 | + List<V> oldValues = map.putIfAbsent(key, new ArrayList<>(values)); |
296 | if (oldValues == null) { | 296 | if (oldValues == null) { |
297 | - map.put(key, new ArrayList<>(values)); | ||
298 | return true; | 297 | return true; |
299 | } | 298 | } |
300 | 299 | ... | ... |
-
Please register or login to post a comment