--- jsr166/src/jsr166x/ConcurrentSkipListMap.java 2009/11/16 04:16:42 1.8 +++ jsr166/src/jsr166x/ConcurrentSkipListMap.java 2011/03/15 19:47:02 1.13 @@ -1,7 +1,7 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ */ package jsr166x; @@ -583,8 +583,8 @@ public class ConcurrentSkipListMap * support the Map.Entry.setValue method. */ static class SnapshotEntry implements Map.Entry { - private final K key; - private final V value; + private final K key; + private final V value; /** * Creates a new entry representing the given key and value. @@ -592,31 +592,31 @@ public class ConcurrentSkipListMap * @param value the value */ SnapshotEntry(K key, V value) { - this.key = key; - this.value = value; - } - - /** - * Returns the key corresponding to this entry. - * - * @return the key corresponding to this entry. - */ + this.key = key; + this.value = value; + } + + /** + * Returns the key corresponding to this entry. + * + * @return the key corresponding to this entry. + */ public K getKey() { return key; } - /** - * Returns the value corresponding to this entry. - * - * @return the value corresponding to this entry. - */ + /** + * Returns the value corresponding to this entry. + * + * @return the value corresponding to this entry. + */ public V getValue() { - return value; + return value; } - /** - * Always fails, throwing UnsupportedOperationException. - * @throws UnsupportedOperationException always. + /** + * Always fails, throwing UnsupportedOperationException. + * @throws UnsupportedOperationException always. */ public V setValue(V value) { throw new UnsupportedOperationException(); @@ -649,7 +649,7 @@ public class ConcurrentSkipListMap * @return a String representation of this entry. */ public String toString() { - return getKey() + "=" + getValue(); + return getKey() + "=" + getValue(); } } @@ -865,7 +865,7 @@ public class ConcurrentSkipListMap } if (c == 0) { Object v = r.node.value; - return (v != null)? (V)v : getUsingFindNode(key); + return (v != null) ? (V)v : getUsingFindNode(key); } bound = rk; } @@ -878,7 +878,7 @@ public class ConcurrentSkipListMap int c = key.compareTo(nk); if (c == 0) { Object v = n.value; - return (v != null)? (V)v : getUsingFindNode(key); + return (v != null) ? (V)v : getUsingFindNode(key); } if (c < 0) return null; @@ -1246,7 +1246,7 @@ public class ConcurrentSkipListMap findFirst(); // retry clearIndexToFirst(); K key = n.key; - return (keyOnly)? key : new SnapshotEntry(key, (V)v); + return keyOnly ? key : new SnapshotEntry(key, (V)v); } } @@ -1306,7 +1306,7 @@ public class ConcurrentSkipListMap Node n = b.next; for (;;) { if (n == null) - return (b.isBaseHeader())? null : b; + return b.isBaseHeader() ? null : b; Node f = n.next; // inconsistent read if (n != b.next) break; @@ -1368,7 +1368,7 @@ public class ConcurrentSkipListMap if (head.right == null) tryReduceLevel(); } - return (keyOnly)? key : new SnapshotEntry(key, (V)v); + return keyOnly ? key : new SnapshotEntry(key, (V)v); } } } @@ -1432,7 +1432,7 @@ public class ConcurrentSkipListMap Node n = b.next; for (;;) { if (n == null) - return ((rel & LT) == 0 || b.isBaseHeader())? null : b; + return ((rel & LT) == 0 || b.isBaseHeader()) ? null : b; Node f = n.next; if (n != b.next) // inconsistent read break; @@ -1448,7 +1448,7 @@ public class ConcurrentSkipListMap (c < 0 && (rel & LT) == 0)) return n; if ( c <= 0 && (rel & LT) != 0) - return (b.isBaseHeader())? null : b; + return b.isBaseHeader() ? null : b; b = n; n = f; } @@ -1476,14 +1476,14 @@ public class ConcurrentSkipListMap * Return ceiling, or first node if key is null */ Node findCeiling(K key) { - return (key == null)? findFirst() : findNear(key, GT|EQ); + return (key == null) ? findFirst() : findNear(key, GT|EQ); } /** * Return lower node, or last node if key is null */ Node findLower(K key) { - return (key == null)? findLast() : findNear(key, LT); + return (key == null) ? findLast() : findNear(key, LT); } /** @@ -1513,7 +1513,7 @@ public class ConcurrentSkipListMap K k = n.key; V v = n.getValidValue(); if (v != null) - return keyOnly? k : new SnapshotEntry(k, v); + return keyOnly ? k : new SnapshotEntry(k, v); } } @@ -1534,7 +1534,7 @@ public class ConcurrentSkipListMap return null; V v = doRemove(k, null); if (v != null) - return (keyOnly)? k : new SnapshotEntry(k, v); + return keyOnly ? k : new SnapshotEntry(k, v); } } @@ -1555,7 +1555,7 @@ public class ConcurrentSkipListMap return null; V v = doRemove(k, null); if (v != null) - return (keyOnly)? k : new SnapshotEntry(k, v); + return keyOnly ? k : new SnapshotEntry(k, v); } } @@ -1847,7 +1847,7 @@ public class ConcurrentSkipListMap * * @param value value whose presence in this Map is to be tested. * @return true if a mapping to value exists; - * false otherwise. + * false otherwise. * @throws NullPointerException if the value is null. */ public boolean containsValue(Object value) { @@ -1883,7 +1883,7 @@ public class ConcurrentSkipListMap if (n.getValidValue() != null) ++count; } - return (count >= Integer.MAX_VALUE)? Integer.MAX_VALUE : (int)count; + return (count >= Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int)count; } /** @@ -2056,17 +2056,17 @@ public class ConcurrentSkipListMap * @return true if the specified object is equal to this map. */ public boolean equals(Object o) { - if (o == this) - return true; - if (!(o instanceof Map)) - return false; - Map t = (Map) o; + if (o == this) + return true; + if (!(o instanceof Map)) + return false; + Map t = (Map) o; try { return (containsAllMappings(this, t) && containsAllMappings(t, this)); - } catch(ClassCastException unused) { + } catch (ClassCastException unused) { return false; - } catch(NullPointerException unused) { + } catch (NullPointerException unused) { return false; } } @@ -2343,7 +2343,7 @@ public class ConcurrentSkipListMap */ public K ceilingKey(K key) { Node n = findNear(key, GT|EQ); - return (n == null)? null : n.key; + return (n == null) ? null : n.key; } /** @@ -2376,7 +2376,7 @@ public class ConcurrentSkipListMap */ public K lowerKey(K key) { Node n = findNear(key, LT); - return (n == null)? null : n.key; + return (n == null) ? null : n.key; } /** @@ -2410,7 +2410,7 @@ public class ConcurrentSkipListMap */ public K floorKey(K key) { Node n = findNear(key, LT|EQ); - return (n == null)? null : n.key; + return (n == null) ? null : n.key; } /** @@ -2443,7 +2443,7 @@ public class ConcurrentSkipListMap */ public K higherKey(K key) { Node n = findNear(key, GT); - return (n == null)? null : n.key; + return (n == null) ? null : n.key; } /** @@ -2525,8 +2525,8 @@ public class ConcurrentSkipListMap Node last; /** the next node to return from next(); */ Node next; - /** Cache of next value field to maintain weak consistency */ - Object nextValue; + /** Cache of next value field to maintain weak consistency */ + Object nextValue; Iter() {} @@ -2537,7 +2537,7 @@ public class ConcurrentSkipListMap /** initialize ascending iterator for entire range */ final void initAscending() { for (;;) { - next = findFirst(); + next = findFirst(); if (next == null) break; nextValue = next.value; @@ -2553,7 +2553,7 @@ public class ConcurrentSkipListMap */ final void initAscending(K least, K fence) { for (;;) { - next = findCeiling(least); + next = findCeiling(least); if (next == null) break; nextValue = next.value; @@ -2571,7 +2571,7 @@ public class ConcurrentSkipListMap if ((last = next) == null) throw new NoSuchElementException(); for (;;) { - next = next.next; + next = next.next; if (next == null) break; nextValue = next.value; @@ -2587,7 +2587,7 @@ public class ConcurrentSkipListMap if ((last = next) == null) throw new NoSuchElementException(); for (;;) { - next = next.next; + next = next.next; if (next == null) break; nextValue = next.value; @@ -2604,7 +2604,7 @@ public class ConcurrentSkipListMap /** initialize descending iterator for entire range */ final void initDescending() { for (;;) { - next = findLast(); + next = findLast(); if (next == null) break; nextValue = next.value; @@ -2621,7 +2621,7 @@ public class ConcurrentSkipListMap */ final void initDescending(K least, K fence) { for (;;) { - next = findLower(fence); + next = findLower(fence); if (next == null) break; nextValue = next.value; @@ -2641,7 +2641,7 @@ public class ConcurrentSkipListMap throw new NoSuchElementException(); K k = last.key; for (;;) { - next = findNear(k, LT); + next = findNear(k, LT); if (next == null) break; nextValue = next.value; @@ -2658,7 +2658,7 @@ public class ConcurrentSkipListMap throw new NoSuchElementException(); K k = last.key; for (;;) { - next = findNear(k, LT); + next = findNear(k, LT); if (next == null) break; nextValue = next.value; @@ -2781,7 +2781,7 @@ public class ConcurrentSkipListMap Object v = lastValue; if (last == null || v == null) throw new IllegalStateException(); - return (V)v; + return (V)v; } public V setValue(V value) { @@ -2810,7 +2810,7 @@ public class ConcurrentSkipListMap // If not acting as entry, just use default. if (last == null) return super.toString(); - return getKey() + "=" + getValue(); + return getKey() + "=" + getValue(); } } @@ -3050,7 +3050,7 @@ public class ConcurrentSkipListMap * Creates a new submap. * @param least inclusive least value, or null if from start * @param fence exclusive upper bound or null if to end - * @throws IllegalArgumentException if least and fence nonnull + * @throws IllegalArgumentException if least and fence non-null * and least greater than fence */ ConcurrentSkipListSubMap(ConcurrentSkipListMap map, @@ -3128,7 +3128,7 @@ public class ConcurrentSkipListMap public V get(Object key) { K k = (K)key; - return ((!inHalfOpenRange(k)) ? null : m.get(k)); + return (!inHalfOpenRange(k)) ? null : m.get(k); } public V put(K key, V value) { @@ -3138,7 +3138,7 @@ public class ConcurrentSkipListMap public V remove(Object key) { K k = (K)key; - return (!inHalfOpenRange(k))? null : m.remove(k); + return (!inHalfOpenRange(k)) ? null : m.remove(k); } public int size() { @@ -3149,7 +3149,8 @@ public class ConcurrentSkipListMap if (n.getValidValue() != null) ++count; } - return count >= Integer.MAX_VALUE? Integer.MAX_VALUE : (int)count; + return (count >= Integer.MAX_VALUE) ? + Integer.MAX_VALUE : (int)count; } public boolean isEmpty() {