RFR 8078645: removeIf(filter) in ConcurrentHashMap removes entries for which filter is false (original) (raw)

Martin Buchholz martinrb at google.com
Tue May 5 05:54:49 UTC 2015


One query in ConcurrentSkipListMap, we have: 2500 // else use iterator 2501 @SuppressWarnings("unchecked") Iterator<Map.Entry<Object,E>> it = 2502 ((SubMap<Object,E>)m).entryIterator(); and then 2578 // else use iterator 2579 Iterator<Map.Entry<K1,V1>> it = ((SubMap<K1,V1>)m).entryIterator(); why does only the former require the "unchecked" warning suppression?

Good question. I think it's a small but clear improvement to consistently use K,V on view subclasses, allowing a few @SuppressWarnings to be removed:

Index: src/main/java/util/concurrent/ConcurrentSkipListMap.java

RCS file: /export/home/jsr166/jsr166/jsr166/src/main/java/util/concurrent/ConcurrentSkipListMap.java,v retrieving revision 1.146 diff -u -r1.146 ConcurrentSkipListMap.java --- src/main/java/util/concurrent/ConcurrentSkipListMap.java 3 May 2015 12:09:30 -0000 1.146 +++ src/main/java/util/concurrent/ConcurrentSkipListMap.java 5 May 2015 05:52:59 -0000 @@ -346,11 +346,11 @@ final Comparator<? super K> comparator;

 /** Lazily initialized key set */

@@ -1798,13 +1798,13 @@ * @return a navigable set view of the keys in this map */ public NavigableSet keySet() {

@@ -1827,8 +1827,8 @@ * weakly consistent. */ public Collection values() {

@@ -2341,36 +2341,35 @@ return list; }

}

}

((ConcurrentSkipListMap.SubMap<E,Object>)m).keyIterator();

((ConcurrentSkipListMap.SubMap<K,V>)m).keyIterator(); } public boolean equals(Object o) { if (o == this) @@ -2388,54 +2387,53 @@ } public Object[] toArray() { return toList(this).toArray(); } public T[] toArray(T[] a) { return toList(this).toArray(a); }

@@ -2452,24 +2450,23 @@ public Object[] toArray() { return toList(this).toArray(); } public T[] toArray(T[] a) { return toList(this).toArray(a); } @SuppressWarnings("unchecked")

((ConcurrentSkipListMap<?,E>)m).removeValueIf(filter);

((ConcurrentSkipListMap<K,V>)m).removeValueIf(filter); // else use iterator

it =

@@ -2477,24 +2474,23 @@ } }

AbstractSet<Map.Entry<K1,V1>> {

@@ -2530,22 +2526,22 @@ public Object[] toArray() { return toList(this).toArray(); } public T[] toArray(T[] a) { return toList(this).toArray(a); } @SuppressWarnings("unchecked")

((ConcurrentSkipListMap<K1,V1>)m).entrySpliterator();

((ConcurrentSkipListMap<K1,V1>)m).removeEntryIf(filter);

((ConcurrentSkipListMap<K,V>)m).removeEntryIf(filter); // else use iterator

((SubMap<K1,V1>)m).entryIterator();

@@ -2583,7 +2579,7 @@ private final boolean isDescending;

     // Lazily initialized view holders

@@ -3051,18 +3047,18 @@ /* ---------------- Submap Views -------------- */

     public NavigableSet<K> keySet() {


More information about the core-libs-dev mailing list