--- a/jdk/src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java Fri Dec 09 12:56:22 2011 -0800
+++ b/jdk/src/share/classes/java/util/concurrent/ConcurrentSkipListMap.java Mon Dec 12 10:45:54 2011 +0000
@@ -35,7 +35,6 @@
package java.util.concurrent;
import java.util.*;
-import java.util.concurrent.atomic.*;
/**
* A scalable concurrent {@link ConcurrentNavigableMap} implementation.
@@ -90,6 +89,7 @@
* @param <V> the type of mapped values
* @since 1.6
*/
+@SuppressWarnings("unchecked")
public class ConcurrentSkipListMap<K,V> extends AbstractMap<K,V>
implements ConcurrentNavigableMap<K,V>,
Cloneable,
@@ -352,11 +352,11 @@
private transient int randomSeed;
/** Lazily initialized key set */
- private transient KeySet keySet;
+ private transient KeySet<K> keySet;
/** Lazily initialized entry set */
- private transient EntrySet entrySet;
+ private transient EntrySet<K,V> entrySet;
/** Lazily initialized values collection */
- private transient Values values;
+ private transient Values<V> values;
/** Lazily initialized descending key set */
private transient ConcurrentNavigableMap<K,V> descendingMap;
@@ -517,7 +517,7 @@
static {
try {
UNSAFE = sun.misc.Unsafe.getUnsafe();
- Class k = Node.class;
+ Class<?> k = Node.class;
valueOffset = UNSAFE.objectFieldOffset
(k.getDeclaredField("value"));
nextOffset = UNSAFE.objectFieldOffset
@@ -597,7 +597,7 @@
static {
try {
UNSAFE = sun.misc.Unsafe.getUnsafe();
- Class k = Index.class;
+ Class<?> k = Index.class;
rightOffset = UNSAFE.objectFieldOffset
(k.getDeclaredField("right"));
} catch (Exception e) {
@@ -933,7 +933,7 @@
* direction.
*/
level = max + 1;
- Index<K,V>[] idxs = (Index<K,V>[])new Index[level+1];
+ Index<K,V>[] idxs = (Index<K,V>[])new Index<?,?>[level+1];
Index<K,V> idx = null;
for (int i = 1; i <= level; ++i)
idxs[i] = idx = new Index<K,V>(z, idx, null);
@@ -1436,16 +1436,16 @@
* @return a shallow copy of this map
*/
public ConcurrentSkipListMap<K,V> clone() {
- ConcurrentSkipListMap<K,V> clone = null;
try {
- clone = (ConcurrentSkipListMap<K,V>) super.clone();
+ @SuppressWarnings("unchecked")
+ ConcurrentSkipListMap<K,V> clone =
+ (ConcurrentSkipListMap<K,V>) super.clone();
+ clone.initialize();
+ clone.buildFromSorted(this);
+ return clone;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
-
- clone.initialize();
- clone.buildFromSorted(this);
- return clone;
}
/**
@@ -1507,7 +1507,7 @@
/* ---------------- Serialization -------------- */
/**
- * Save the state of this map to a stream.
+ * Saves the state of this map to a stream (that is, serializes it).
*
* @serialData The key (Object) and value (Object) for each
* key-value mapping represented by the map, followed by
@@ -1532,7 +1532,9 @@
}
/**
- * Reconstitute the map from a stream.
+ * Reconstitutes the map from a stream (that is, deserializes it).
+ *
+ * @param s the stream
*/
private void readObject(final java.io.ObjectInputStream s)
throws java.io.IOException, ClassNotFoundException {
@@ -1755,13 +1757,13 @@
* @return a navigable set view of the keys in this map
*/
public NavigableSet<K> keySet() {
- KeySet ks = keySet;
- return (ks != null) ? ks : (keySet = new KeySet(this));
+ KeySet<K> ks = keySet;
+ return (ks != null) ? ks : (keySet = new KeySet<K>(this));
}
public NavigableSet<K> navigableKeySet() {
- KeySet ks = keySet;
- return (ks != null) ? ks : (keySet = new KeySet(this));
+ KeySet<K> ks = keySet;
+ return (ks != null) ? ks : (keySet = new KeySet<K>(this));
}
/**
@@ -1783,8 +1785,8 @@
* reflect any modifications subsequent to construction.
*/
public Collection<V> values() {
- Values vs = values;
- return (vs != null) ? vs : (values = new Values(this));
+ Values<V> vs = values;
+ return (vs != null) ? vs : (values = new Values<V>(this));
}
/**
@@ -1812,8 +1814,8 @@
* sorted in ascending key order
*/
public Set<Map.Entry<K,V>> entrySet() {
- EntrySet es = entrySet;
- return (es != null) ? es : (entrySet = new EntrySet(this));
+ EntrySet<K,V> es = entrySet;
+ return (es != null) ? es : (entrySet = new EntrySet<K,V>(this));
}
public ConcurrentNavigableMap<K,V> descendingMap() {
@@ -2304,8 +2306,8 @@
static final class KeySet<E>
extends AbstractSet<E> implements NavigableSet<E> {
- private final ConcurrentNavigableMap<E,Object> m;
- KeySet(ConcurrentNavigableMap<E,Object> map) { m = map; }
+ private final ConcurrentNavigableMap<E,?> m;
+ KeySet(ConcurrentNavigableMap<E,?> map) { m = map; }
public int size() { return m.size(); }
public boolean isEmpty() { return m.isEmpty(); }
public boolean contains(Object o) { return m.containsKey(o); }
@@ -2319,11 +2321,11 @@
public E first() { return m.firstKey(); }
public E last() { return m.lastKey(); }
public E pollFirst() {
- Map.Entry<E,Object> e = m.pollFirstEntry();
+ Map.Entry<E,?> e = m.pollFirstEntry();
return (e == null) ? null : e.getKey();
}
public E pollLast() {
- Map.Entry<E,Object> e = m.pollLastEntry();
+ Map.Entry<E,?> e = m.pollLastEntry();
return (e == null) ? null : e.getKey();
}
public Iterator<E> iterator() {
@@ -2374,20 +2376,20 @@
return tailSet(fromElement, true);
}
public NavigableSet<E> descendingSet() {
- return new KeySet(m.descendingMap());
+ return new KeySet<E>(m.descendingMap());
}
}
static final class Values<E> extends AbstractCollection<E> {
- private final ConcurrentNavigableMap<Object, E> m;
- Values(ConcurrentNavigableMap<Object, E> map) {
+ private final ConcurrentNavigableMap<?, E> m;
+ Values(ConcurrentNavigableMap<?, E> map) {
m = map;
}
public Iterator<E> iterator() {
if (m instanceof ConcurrentSkipListMap)
- return ((ConcurrentSkipListMap<Object,E>)m).valueIterator();
+ return ((ConcurrentSkipListMap<?,E>)m).valueIterator();
else
- return ((SubMap<Object,E>)m).valueIterator();
+ return ((SubMap<?,E>)m).valueIterator();
}
public boolean isEmpty() {
return m.isEmpty();
@@ -2421,14 +2423,14 @@
public boolean contains(Object o) {
if (!(o instanceof Map.Entry))
return false;
- Map.Entry<K1,V1> e = (Map.Entry<K1,V1>)o;
+ Map.Entry<?,?> e = (Map.Entry<?,?>)o;
V1 v = m.get(e.getKey());
return v != null && v.equals(e.getValue());
}
public boolean remove(Object o) {
if (!(o instanceof Map.Entry))
return false;
- Map.Entry<K1,V1> e = (Map.Entry<K1,V1>)o;
+ Map.Entry<?,?> e = (Map.Entry<?,?>)o;
return m.remove(e.getKey(),
e.getValue());
}
@@ -2568,9 +2570,9 @@
if (lo == null)
return m.findFirst();
else if (loInclusive)
- return m.findNear(lo, m.GT|m.EQ);
+ return m.findNear(lo, GT|EQ);
else
- return m.findNear(lo, m.GT);
+ return m.findNear(lo, GT);
}
/**
@@ -2581,9 +2583,9 @@
if (hi == null)
return m.findLast();
else if (hiInclusive)
- return m.findNear(hi, m.LT|m.EQ);
+ return m.findNear(hi, LT|EQ);
else
- return m.findNear(hi, m.LT);
+ return m.findNear(hi, LT);
}
/**
@@ -2665,15 +2667,15 @@
*/
private Map.Entry<K,V> getNearEntry(K key, int rel) {
if (isDescending) { // adjust relation for direction
- if ((rel & m.LT) == 0)
- rel |= m.LT;
+ if ((rel & LT) == 0)
+ rel |= LT;
else
- rel &= ~m.LT;
+ rel &= ~LT;
}
if (tooLow(key))
- return ((rel & m.LT) != 0) ? null : lowestEntry();
+ return ((rel & LT) != 0) ? null : lowestEntry();
if (tooHigh(key))
- return ((rel & m.LT) != 0) ? highestEntry() : null;
+ return ((rel & LT) != 0) ? highestEntry() : null;
for (;;) {
Node<K,V> n = m.findNear(key, rel);
if (n == null || !inBounds(n.key))
@@ -2688,13 +2690,13 @@
// Almost the same as getNearEntry, except for keys
private K getNearKey(K key, int rel) {
if (isDescending) { // adjust relation for direction
- if ((rel & m.LT) == 0)
- rel |= m.LT;
+ if ((rel & LT) == 0)
+ rel |= LT;
else
- rel &= ~m.LT;
+ rel &= ~LT;
}
if (tooLow(key)) {
- if ((rel & m.LT) == 0) {
+ if ((rel & LT) == 0) {
ConcurrentSkipListMap.Node<K,V> n = loNode();
if (isBeforeEnd(n))
return n.key;
@@ -2702,7 +2704,7 @@
return null;
}
if (tooHigh(key)) {
- if ((rel & m.LT) != 0) {
+ if ((rel & LT) != 0) {
ConcurrentSkipListMap.Node<K,V> n = hiNode();
if (n != null) {
K last = n.key;
@@ -2734,7 +2736,7 @@
public V get(Object key) {
if (key == null) throw new NullPointerException();
K k = (K)key;
- return ((!inBounds(k)) ? null : m.get(k));
+ return (!inBounds(k)) ? null : m.get(k);
}
public V put(K key, V value) {
@@ -2901,35 +2903,35 @@
/* ---------------- Relational methods -------------- */
public Map.Entry<K,V> ceilingEntry(K key) {
- return getNearEntry(key, (m.GT|m.EQ));
+ return getNearEntry(key, GT|EQ);
}
public K ceilingKey(K key) {
- return getNearKey(key, (m.GT|m.EQ));
+ return getNearKey(key, GT|EQ);
}
public Map.Entry<K,V> lowerEntry(K key) {
- return getNearEntry(key, (m.LT));
+ return getNearEntry(key, LT);
}
public K lowerKey(K key) {
- return getNearKey(key, (m.LT));
+ return getNearKey(key, LT);
}
public Map.Entry<K,V> floorEntry(K key) {
- return getNearEntry(key, (m.LT|m.EQ));
+ return getNearEntry(key, LT|EQ);
}
public K floorKey(K key) {
- return getNearKey(key, (m.LT|m.EQ));
+ return getNearKey(key, LT|EQ);
}
public Map.Entry<K,V> higherEntry(K key) {
- return getNearEntry(key, (m.GT));
+ return getNearEntry(key, GT);
}
public K higherKey(K key) {
- return getNearKey(key, (m.GT));
+ return getNearKey(key, GT);
}
public K firstKey() {
@@ -2960,22 +2962,22 @@
public NavigableSet<K> keySet() {
KeySet<K> ks = keySetView;
- return (ks != null) ? ks : (keySetView = new KeySet(this));
+ return (ks != null) ? ks : (keySetView = new KeySet<K>(this));
}
public NavigableSet<K> navigableKeySet() {
KeySet<K> ks = keySetView;
- return (ks != null) ? ks : (keySetView = new KeySet(this));
+ return (ks != null) ? ks : (keySetView = new KeySet<K>(this));
}
public Collection<V> values() {
Collection<V> vs = valuesView;
- return (vs != null) ? vs : (valuesView = new Values(this));
+ return (vs != null) ? vs : (valuesView = new Values<V>(this));
}
public Set<Map.Entry<K,V>> entrySet() {
Set<Map.Entry<K,V>> es = entrySetView;
- return (es != null) ? es : (entrySetView = new EntrySet(this));
+ return (es != null) ? es : (entrySetView = new EntrySet<K,V>(this));
}
public NavigableSet<K> descendingKeySet() {
@@ -3109,7 +3111,7 @@
static {
try {
UNSAFE = sun.misc.Unsafe.getUnsafe();
- Class k = ConcurrentSkipListMap.class;
+ Class<?> k = ConcurrentSkipListMap.class;
headOffset = UNSAFE.objectFieldOffset
(k.getDeclaredField("head"));
} catch (Exception e) {