--- jsr166/src/extra166y/CustomConcurrentHashMap.java 2009/06/30 14:56:53 1.2 +++ jsr166/src/extra166y/CustomConcurrentHashMap.java 2009/07/22 17:50:01 1.3 @@ -31,17 +31,17 @@ import sun.misc.Unsafe; * establish a computed value, along with * RemappingFunctions that can be used in method * {@link CustomConcurrentHashMap#compute} to atomically - * replace values. + * replace values. * *
  • Factory methods returning specialized forms for int * keys and/or values, that may be more space-efficient * * - * + * * Per-map settings are established in constructors, as in the * following usages (that assume static imports to simplify expression * of configuration parameters): - * + * *
      * {@code
      * identityMap = new CustomConcurrentHashMap
    @@ -55,7 +55,7 @@ import sun.misc.Unsafe;
      *          public boolean equal(Person k, Object x) {
      *            return x instanceOf Person && k.name.equals(((Person)x).name);
      *          }
    - *          public int hash(Object x) { 
    + *          public int hash(Object x) {
      *             return (x instanceOf Person)? ((Person)x).name.hashCode() : 0;
      *          }
      *        },
    @@ -69,7 +69,7 @@ import sun.misc.Unsafe;
      * and identity-based equality for keys. The third usage
      * illustrates a map with a custom Equivalence that looks only at the
      * name field of a (fictional) Person class.
    - * 
    + *
      * 

    This class also includes nested class {@link KeySet} * that provides space-efficient Set views of maps, also supporting * method intern, which may be of use in canonicalizing @@ -126,7 +126,7 @@ public class CustomConcurrentHashMap, Serializable { private static final long serialVersionUID = 7259069246764182397L; public final boolean equal(Object a, Object b) { return a == b; } public final int hash(Object a) { return System.identityHashCode(a); } } - static final class EquivalenceUsingEquals + static final class EquivalenceUsingEquals implements Equivalence, Serializable { private static final long serialVersionUID = 7259069247764182397L; public final boolean equal(Object a, Object b) { return a.equals(b); } @@ -212,19 +212,19 @@ public class CustomConcurrentHashMap IDENTITY = + public static final Equivalence IDENTITY = new EquivalenceUsingIdentity(); - + /** * An Equivalence object performing {@link Object#equals} based comparisons * and using {@link Object#hashCode} hashing */ - public static final Equivalence EQUALS = + public static final Equivalence EQUALS = new EquivalenceUsingEquals(); /** * A function computing a mapping from the given key to a value, - * or null if there is no mapping. + * or null if there is no mapping. */ public static interface MappingFunction { /** @@ -277,12 +277,12 @@ public class CustomConcurrentHashMap= MAX_SEGMENT_CAPACITY) return oldTable; - Node[] newTable = + Node[] newTable = (Node[])new Node[oldCapacity<<1]; int sizeMask = newTable.length - 1; NodeFactory fac = cchm.factory; @@ -436,7 +436,7 @@ public class CustomConcurrentHashMap keyEquivalence; - + /** * Equivalence object for values */ final Equivalence valueEquivalence; - + /** * The initial size of Segment tables when they are first constructed */ @@ -515,9 +515,9 @@ public class CustomConcurrentHashMap valueEquivalence, int expectedSize) { - this(keyStrength.getName(), keyEquivalence, + this(keyStrength.getName(), keyEquivalence, valueStrength.getName(), valueEquivalence, expectedSize); } @@ -600,7 +600,7 @@ public class CustomConcurrentHashMap keyEquivalence, int expectedSize) { return new CustomConcurrentHashMap - (keyStrength.getName(), keyEquivalence, INT_STRING, EQUALS, + (keyStrength.getName(), keyEquivalence, INT_STRING, EQUALS, expectedSize); } @@ -614,7 +614,7 @@ public class CustomConcurrentHashMap newIntKeyIntValueMap(int expectedSize) { return new CustomConcurrentHashMap - (INT_STRING, EQUALS, INT_STRING, EQUALS, + (INT_STRING, EQUALS, INT_STRING, EQUALS, expectedSize); } @@ -662,8 +662,8 @@ public class CustomConcurrentHashMapnull if the computation * returned null. - * @throws NullPointerException if the specified key or mappingFunction + * @throws NullPointerException if the specified key or mappingFunction * is null, * @throws RuntimeException or Error if the mappingFunction does so, * in which case the mapping is left unestablished. @@ -1111,7 +1111,7 @@ public class CustomConcurrentHashMap - * + * * except that the action is performed atomically. Some attemmpted * operations on this map by other threads may be blocked while * computation is in progress. @@ -1161,8 +1161,8 @@ public class CustomConcurrentHashMapnull if the computation returned null - * @throws NullPointerException if the specified key or remappingFunction + * null if the computation returned null + * @throws NullPointerException if the specified key or remappingFunction * is null, * @throws RuntimeException or Error if the remappingFunction does so, * in which case the mapping is left in its previous state @@ -1183,7 +1183,7 @@ public class CustomConcurrentHashMap= 0) { Segment seg = segments[nextSegmentIndex--]; Node[] t; - if (seg != null && + if (seg != null && (t = seg.getTableForTraversal()) != null) { currentTable = t; nextTableIndex = t.length - 1; @@ -1287,7 +1287,7 @@ public class CustomConcurrentHashMap nextEntry() { if (nextNode == null) throw new NoSuchElementException(); - WriteThroughEntry e = new WriteThroughEntry((K)nextKey, + WriteThroughEntry e = new WriteThroughEntry((K)nextKey, (V)nextValue); advance(); return e; @@ -1330,10 +1330,10 @@ public class CustomConcurrentHashMap { - public K next() { - return super.nextKey(); + public K next() { + return super.nextKey(); } } @@ -1341,14 +1341,14 @@ public class CustomConcurrentHashMap { - public V next() { - return super.nextValue(); + public V next() { + return super.nextValue(); } } - final class EntryIterator extends HashIterator + final class EntryIterator extends HashIterator implements Iterator> { public Map.Entry next() { return super.nextEntry(); @@ -1403,7 +1403,7 @@ public class CustomConcurrentHashMap e = (Map.Entry)o; V v = CustomConcurrentHashMap.this.get(e.getKey()); - return v != null && + return v != null && valueEquivalence.equal(v, e.getValue()); } public boolean remove(Object o) { @@ -1501,7 +1501,7 @@ public class CustomConcurrentHashMap m = (Map) o; @@ -1602,11 +1602,11 @@ public class CustomConcurrentHashMap equivalence, int expectedSize) { this.cchm = new CustomConcurrentHashMap - (strength.getName(), equivalence, + (strength.getName(), equivalence, SELF_STRING, equivalence, expectedSize); } @@ -1614,15 +1614,15 @@ public class CustomConcurrentHashMaptrue if this set contains an * element equivalent to the given element with respect @@ -1633,7 +1633,7 @@ public class CustomConcurrentHashMapweakly consistent iterator over the * elements in this set, that may reflect some, all or none of @@ -1644,7 +1644,7 @@ public class CustomConcurrentHashMap iterator() { return cchm.keyIterator(); } - + /** * Adds the specified element to this set if there is not * already an element equivalent to the given element with @@ -1686,7 +1686,7 @@ public class CustomConcurrentHashMap r = q.remove(); if (r instanceof Reclaimable) ((Reclaimable)r).onReclamation(); - } catch (InterruptedException e) { - /* ignore */ + } catch (InterruptedException e) { + /* ignore */ } } } @@ -1758,29 +1758,29 @@ public class CustomConcurrentHashMap