ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/jsr166e/LongAdderTable.java
(Generate patch)

Comparing jsr166/src/jsr166e/LongAdderTable.java (file contents):
Revision 1.6 by jsr166, Sat Sep 10 01:44:53 2011 UTC vs.
Revision 1.11 by jsr166, Sun Jan 18 20:17:33 2015 UTC

# Line 5 | Line 5
5   */
6  
7   package jsr166e;
8 +
9   import jsr166e.LongAdder;
10   import java.util.Map;
11   import java.util.Set;
# Line 12 | Line 13 | import java.io.Serializable;
13  
14   /**
15   * A keyed table of adders, that may be useful in computing frequency
16 < * counts and histograms, or may be used a form of multiset.  A {@link
17 < * LongAdder} is associated with each key. Keys are added to the table
18 < * implicitly upon any attempt to update, or may be added explicitly
19 < * using method {@link #install}.
16 > * counts and histograms, or may be used as a form of multiset.  A
17 > * {@link LongAdder} is associated with each key. Keys are added to
18 > * the table implicitly upon any attempt to update, or may be added
19 > * explicitly using method {@link #install}.
20   *
21   * <p><em>jsr166e note: This class is targeted to be placed in
22 < * java.util.concurrent.atomic<em>
22 > * java.util.concurrent.atomic.</em>
23   *
24   * @since 1.8
25   * @author Doug Lea
# Line 31 | Line 32 | public class LongAdderTable<K> implement
32      private final ConcurrentHashMapV8<K, LongAdder> map;
33  
34      static final class CreateAdder
35 <        implements ConcurrentHashMapV8.MappingFunction<Object, LongAdder> {
36 <        public LongAdder map(Object unused) { return new LongAdder(); }
35 >        implements ConcurrentHashMapV8.Fun<Object, LongAdder> {
36 >        public LongAdder apply(Object unused) { return new LongAdder(); }
37      }
38  
39      private static final CreateAdder createAdder = new CreateAdder();
# Line 53 | Line 54 | public class LongAdderTable<K> implement
54       * @return the adder associated with the key
55       */
56      public LongAdder install(K key) {
57 <        LongAdder a = map.get(key);
57 <        if (a == null) {
58 <            LongAdder r = new LongAdder();
59 <            if ((a = map.putIfAbsent(key, r)) == null)
60 <                a = r;
61 <        }
62 <        return a;
57 >        return map.computeIfAbsent(key, createAdder);
58      }
59  
60      /**
# Line 71 | Line 66 | public class LongAdderTable<K> implement
66       * @param x the value to add
67       */
68      public void add(K key, long x) {
69 <        LongAdder a = map.get(key);
75 <        if (a == null)
76 <            a = map.computeIfAbsent(key, createAdder);
77 <        a.add(x);
69 >        map.computeIfAbsent(key, createAdder).add(x);
70      }
71  
72      /**

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines