ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java
(Generate patch)

Comparing jsr166/src/main/java/util/concurrent/ConcurrentHashMap.java (file contents):
Revision 1.269 by jsr166, Mon Mar 23 18:48:19 2015 UTC vs.
Revision 1.278 by jsr166, Sat Sep 12 21:55:08 2015 UTC

# Line 31 | Line 31 | import java.util.function.DoubleBinaryOp
31   import java.util.function.Function;
32   import java.util.function.IntBinaryOperator;
33   import java.util.function.LongBinaryOperator;
34 + import java.util.function.Predicate;
35   import java.util.function.ToDoubleBiFunction;
36   import java.util.function.ToDoubleFunction;
37   import java.util.function.ToIntBiFunction;
# Line 120 | Line 121 | import java.util.stream.Stream;
121   * being concurrently updated by other threads; for example, when
122   * computing a snapshot summary of the values in a shared registry.
123   * There are three kinds of operation, each with four forms, accepting
124 < * functions with Keys, Values, Entries, and (Key, Value) arguments
125 < * and/or return values. Because the elements of a ConcurrentHashMap
126 < * are not ordered in any particular way, and may be processed in
127 < * different orders in different parallel executions, the correctness
128 < * of supplied functions should not depend on any ordering, or on any
129 < * other objects or values that may transiently change while
130 < * computation is in progress; and except for forEach actions, should
131 < * ideally be side-effect-free. Bulk operations on {@link java.util.Map.Entry}
132 < * objects do not support method {@code setValue}.
124 > * functions with keys, values, entries, and (key, value) pairs as
125 > * arguments and/or return values. Because the elements of a
126 > * ConcurrentHashMap are not ordered in any particular way, and may be
127 > * processed in different orders in different parallel executions, the
128 > * correctness of supplied functions should not depend on any
129 > * ordering, or on any other objects or values that may transiently
130 > * change while computation is in progress; and except for forEach
131 > * actions, should ideally be side-effect-free. Bulk operations on
132 > * {@link java.util.Map.Entry} objects do not support method {@code
133 > * setValue}.
134   *
135   * <ul>
136   * <li> forEach: Perform a given action on each element.
# Line 447 | Line 449 | public class ConcurrentHashMap<K,V> exte
449       *
450       * Maintaining API and serialization compatibility with previous
451       * versions of this class introduces several oddities. Mainly: We
452 <     * leave untouched but unused constructor arguments refering to
452 >     * leave untouched but unused constructor arguments referring to
453       * concurrencyLevel. We accept a loadFactor constructor argument,
454       * but apply it only to initial table capacity (which is the only
455       * time that we can guarantee to honor it.) We also declare an
# Line 1373 | Line 1375 | public class ConcurrentHashMap<K,V> exte
1375              new Segment<?,?>[DEFAULT_CONCURRENCY_LEVEL];
1376          for (int i = 0; i < segments.length; ++i)
1377              segments[i] = new Segment<K,V>(LOAD_FACTOR);
1378 <        s.putFields().put("segments", segments);
1379 <        s.putFields().put("segmentShift", segmentShift);
1380 <        s.putFields().put("segmentMask", segmentMask);
1378 >        java.io.ObjectOutputStream.PutField streamFields = s.putFields();
1379 >        streamFields.put("segments", segments);
1380 >        streamFields.put("segmentShift", segmentShift);
1381 >        streamFields.put("segmentMask", segmentMask);
1382          s.writeFields();
1383  
1384          Node<K,V>[] t;
# Line 1592 | Line 1595 | public class ConcurrentHashMap<K,V> exte
1595      }
1596  
1597      /**
1598 +     * Helper method for EntrySetView.removeIf
1599 +     */
1600 +    boolean removeEntryIf(Predicate<? super Entry<K,V>> function) {
1601 +        if (function == null) throw new NullPointerException();
1602 +        Node<K,V>[] t;
1603 +        boolean removed = false;
1604 +        if ((t = table) != null) {
1605 +            Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
1606 +            for (Node<K,V> p; (p = it.advance()) != null; ) {
1607 +                K k = p.key;
1608 +                V v = p.val;
1609 +                Map.Entry<K,V> e = new AbstractMap.SimpleImmutableEntry<>(k, v);
1610 +                if (function.test(e) && replaceNode(k, null, v) != null)
1611 +                    removed = true;
1612 +            }
1613 +        }
1614 +        return removed;
1615 +    }
1616 +
1617 +    /**
1618 +     * Helper method for ValuesView.removeIf
1619 +     */
1620 +    boolean removeValueIf(Predicate<? super V> function) {
1621 +        if (function == null) throw new NullPointerException();
1622 +        Node<K,V>[] t;
1623 +        boolean removed = false;
1624 +        if ((t = table) != null) {
1625 +            Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
1626 +            for (Node<K,V> p; (p = it.advance()) != null; ) {
1627 +                K k = p.key;
1628 +                V v = p.val;
1629 +                if (function.test(v) && replaceNode(k, null, v) != null)
1630 +                    removed = true;
1631 +            }
1632 +        }
1633 +        return removed;
1634 +    }
1635 +
1636 +    /**
1637       * If the specified key is not already associated with a value,
1638       * attempts to compute its value using the given mapping function
1639       * and enters it into this map unless {@code null}.  The entire
# Line 2034 | Line 2076 | public class ConcurrentHashMap<K,V> exte
2076      // Hashtable legacy methods
2077  
2078      /**
2079 <     * Legacy method testing if some key maps into the specified value
2038 <     * in this table.
2079 >     * Tests if some key maps into the specified value in this table.
2080       *
2081 <     * @deprecated This method is identical in functionality to
2081 >     * <p>Note that this method is identical in functionality to
2082       * {@link #containsValue(Object)}, and exists solely to ensure
2083       * full compatibility with class {@link java.util.Hashtable},
2084 <     * which supported this method prior to introduction of the
2085 <     * Java Collections framework.
2084 >     * which supported this method prior to introduction of the Java
2085 >     * Collections Framework.
2086       *
2087       * @param  value a value to search for
2088       * @return {@code true} if and only if some key maps to the
# Line 2050 | Line 2091 | public class ConcurrentHashMap<K,V> exte
2091       *         {@code false} otherwise
2092       * @throws NullPointerException if the specified value is null
2093       */
2053    @Deprecated
2094      public boolean contains(Object value) {
2095          return containsValue(value);
2096      }
# Line 4669 | Line 4709 | public class ConcurrentHashMap<K,V> exte
4709              throw new UnsupportedOperationException();
4710          }
4711  
4712 +        public boolean removeIf(Predicate<? super V> filter) {
4713 +            return map.removeValueIf(filter);
4714 +        }
4715 +
4716          public Spliterator<V> spliterator() {
4717              Node<K,V>[] t;
4718              ConcurrentHashMap<K,V> m = map;
# Line 4738 | Line 4782 | public class ConcurrentHashMap<K,V> exte
4782              return added;
4783          }
4784  
4785 +        public boolean removeIf(Predicate<? super Entry<K,V>> filter) {
4786 +            return map.removeEntryIf(filter);
4787 +        }
4788 +
4789          public final int hashCode() {
4790              int h = 0;
4791              Node<K,V>[] t;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines