jdk/src/java.base/share/classes/java/util/concurrent/ConcurrentHashMap.java
changeset 30441 415a5242e046
parent 25859 3317bb8137f4
child 30655 d83f50188ca9
equal deleted inserted replaced
30440:376bb53438b7 30441:415a5242e046
    62 import java.util.function.Consumer;
    62 import java.util.function.Consumer;
    63 import java.util.function.DoubleBinaryOperator;
    63 import java.util.function.DoubleBinaryOperator;
    64 import java.util.function.Function;
    64 import java.util.function.Function;
    65 import java.util.function.IntBinaryOperator;
    65 import java.util.function.IntBinaryOperator;
    66 import java.util.function.LongBinaryOperator;
    66 import java.util.function.LongBinaryOperator;
       
    67 import java.util.function.Predicate;
    67 import java.util.function.ToDoubleBiFunction;
    68 import java.util.function.ToDoubleBiFunction;
    68 import java.util.function.ToDoubleFunction;
    69 import java.util.function.ToDoubleFunction;
    69 import java.util.function.ToIntBiFunction;
    70 import java.util.function.ToIntBiFunction;
    70 import java.util.function.ToIntFunction;
    71 import java.util.function.ToIntFunction;
    71 import java.util.function.ToLongBiFunction;
    72 import java.util.function.ToLongBiFunction;
  1617             }
  1618             }
  1618         }
  1619         }
  1619     }
  1620     }
  1620 
  1621 
  1621     /**
  1622     /**
       
  1623      * Helper method for EntrySet.removeIf
       
  1624      */
       
  1625     boolean removeEntryIf(Predicate<? super Entry<K, V>> function) {
       
  1626         if (function == null) throw new NullPointerException();
       
  1627         Node<K,V>[] t;
       
  1628         boolean removed = false;
       
  1629         if ((t = table) != null) {
       
  1630             Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
       
  1631             for (Node<K,V> p; (p = it.advance()) != null; ) {
       
  1632                 K k = p.key;
       
  1633                 V v = p.val;
       
  1634                 Map.Entry<K,V> e = new AbstractMap.SimpleImmutableEntry<>(k, v);
       
  1635                 if (function.test(e) && replaceNode(k, null, v) != null)
       
  1636                     removed = true;
       
  1637             }
       
  1638         }
       
  1639         return removed;
       
  1640     }
       
  1641 
       
  1642     /**
       
  1643      * Helper method for Values.removeIf
       
  1644      */
       
  1645     boolean removeValueIf(Predicate<? super  V> function) {
       
  1646         if (function == null) throw new NullPointerException();
       
  1647         Node<K,V>[] t;
       
  1648         boolean removed = false;
       
  1649         if ((t = table) != null) {
       
  1650             Traverser<K,V> it = new Traverser<K,V>(t, t.length, 0, t.length);
       
  1651             for (Node<K,V> p; (p = it.advance()) != null; ) {
       
  1652                 K k = p.key;
       
  1653                 V v = p.val;
       
  1654                 if (function.test(v) && replaceNode(k, null, v) != null)
       
  1655                     removed = true;
       
  1656             }
       
  1657         }
       
  1658         return removed;
       
  1659     }
       
  1660 
       
  1661     /**
  1622      * If the specified key is not already associated with a value,
  1662      * If the specified key is not already associated with a value,
  1623      * attempts to compute its value using the given mapping function
  1663      * attempts to compute its value using the given mapping function
  1624      * and enters it into this map unless {@code null}.  The entire
  1664      * and enters it into this map unless {@code null}.  The entire
  1625      * method invocation is performed atomically, so the function is
  1665      * method invocation is performed atomically, so the function is
  1626      * applied at most once per key.  Some attempted update operations
  1666      * applied at most once per key.  Some attempted update operations
  4688         }
  4728         }
  4689         public final boolean addAll(Collection<? extends V> c) {
  4729         public final boolean addAll(Collection<? extends V> c) {
  4690             throw new UnsupportedOperationException();
  4730             throw new UnsupportedOperationException();
  4691         }
  4731         }
  4692 
  4732 
       
  4733         public boolean removeIf(Predicate<? super V> filter) {
       
  4734             return map.removeValueIf(filter);
       
  4735         }
       
  4736 
  4693         public Spliterator<V> spliterator() {
  4737         public Spliterator<V> spliterator() {
  4694             Node<K,V>[] t;
  4738             Node<K,V>[] t;
  4695             ConcurrentHashMap<K,V> m = map;
  4739             ConcurrentHashMap<K,V> m = map;
  4696             long n = m.sumCount();
  4740             long n = m.sumCount();
  4697             int f = (t = m.table) == null ? 0 : t.length;
  4741             int f = (t = m.table) == null ? 0 : t.length;
  4755             for (Entry<K,V> e : c) {
  4799             for (Entry<K,V> e : c) {
  4756                 if (add(e))
  4800                 if (add(e))
  4757                     added = true;
  4801                     added = true;
  4758             }
  4802             }
  4759             return added;
  4803             return added;
       
  4804         }
       
  4805 
       
  4806         public boolean removeIf(Predicate<? super Entry<K, V>> filter) {
       
  4807             return map.removeEntryIf(filter);
  4760         }
  4808         }
  4761 
  4809 
  4762         public final int hashCode() {
  4810         public final int hashCode() {
  4763             int h = 0;
  4811             int h = 0;
  4764             Node<K,V>[] t;
  4812             Node<K,V>[] t;