--- jsr166/src/jsr166e/LongAdderTable.java 2011/09/10 01:44:53 1.6 +++ jsr166/src/jsr166e/LongAdderTable.java 2015/01/18 20:17:33 1.11 @@ -5,6 +5,7 @@ */ package jsr166e; + import jsr166e.LongAdder; import java.util.Map; import java.util.Set; @@ -12,13 +13,13 @@ import java.io.Serializable; /** * A keyed table of adders, that may be useful in computing frequency - * counts and histograms, or may be used a form of multiset. A {@link - * LongAdder} is associated with each key. Keys are added to the table - * implicitly upon any attempt to update, or may be added explicitly - * using method {@link #install}. + * counts and histograms, or may be used as a form of multiset. A + * {@link LongAdder} is associated with each key. Keys are added to + * the table implicitly upon any attempt to update, or may be added + * explicitly using method {@link #install}. * *

jsr166e note: This class is targeted to be placed in - * java.util.concurrent.atomic + * java.util.concurrent.atomic. * * @since 1.8 * @author Doug Lea @@ -31,8 +32,8 @@ public class LongAdderTable implement private final ConcurrentHashMapV8 map; static final class CreateAdder - implements ConcurrentHashMapV8.MappingFunction { - public LongAdder map(Object unused) { return new LongAdder(); } + implements ConcurrentHashMapV8.Fun { + public LongAdder apply(Object unused) { return new LongAdder(); } } private static final CreateAdder createAdder = new CreateAdder(); @@ -53,13 +54,7 @@ public class LongAdderTable implement * @return the adder associated with the key */ public LongAdder install(K key) { - LongAdder a = map.get(key); - if (a == null) { - LongAdder r = new LongAdder(); - if ((a = map.putIfAbsent(key, r)) == null) - a = r; - } - return a; + return map.computeIfAbsent(key, createAdder); } /** @@ -71,10 +66,7 @@ public class LongAdderTable implement * @param x the value to add */ public void add(K key, long x) { - LongAdder a = map.get(key); - if (a == null) - a = map.computeIfAbsent(key, createAdder); - a.add(x); + map.computeIfAbsent(key, createAdder).add(x); } /**