From dc0a0df8d6d577ea43d34b068c2a679f864a42f8 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Sun, 4 Nov 2012 14:45:33 +0100 Subject: [PATCH] Polish Javadoc for ConcurrentReferenceHashMap Issue: SPR-9796 --- .../util/ConcurrentReferenceHashMap.java | 37 ++++++++++--------- .../util/ConcurrentReferenceHashMapTests.java | 2 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java index 2dc03b5076f..20425d4ffdc 100644 --- a/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java +++ b/spring-core/src/main/java/org/springframework/util/ConcurrentReferenceHashMap.java @@ -35,7 +35,7 @@ import java.util.concurrent.locks.ReentrantLock; /** * A {@link ConcurrentHashMap} that uses {@link ReferenceType#SOFT soft} or - * {@link ReferenceType#WEAK weak} references for both {@code keys} and {@code values}. + * {@linkplain ReferenceType#WEAK weak} references for both {@code keys} and {@code values}. * *

This class can be used as an alternative to * {@code Collections.synchronizedMap(new WeakHashMap>())} in order to @@ -45,11 +45,11 @@ import java.util.concurrent.locks.ReentrantLock; * *

NOTE: The use of references means that there is no guarantee that items * placed into the map will be subsequently available. The garbage collector may discard - * references at any time, so it may appear that a unknown thread is silently removing + * references at any time, so it may appear that an unknown thread is silently removing * entries. * *

If not explicitly specified this implementation will use - * {@link SoftReference soft entry references}. + * {@linkplain SoftReference soft entry references}. * * @param The key type * @param The value type @@ -73,7 +73,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** - * Array of segment indexed using the high order bits from the hash. + * Array of segments indexed using the high order bits from the hash. */ private final Segment[] segments; @@ -96,7 +96,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** - * Create a new {@link ConcurrentReferenceHashMap} instance. + * Create a new {@code ConcurrentReferenceHashMap} instance. */ public ConcurrentReferenceHashMap() { this(DEFAULT_INITIAL_CAPACITY, DEFAULT_LOAD_FACTOR, DEFAULT_CONCURRENCY_LEVEL, @@ -104,7 +104,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } /** - * Create a new {@link ConcurrentReferenceHashMap} instance. + * Create a new {@code ConcurrentReferenceHashMap} instance. * @param initialCapacity the initial capacity of the map */ public ConcurrentReferenceHashMap(int initialCapacity) { @@ -113,7 +113,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } /** - * Create a new {@link ConcurrentReferenceHashMap} instance. + * Create a new {@code ConcurrentReferenceHashMap} instance. * @param initialCapacity the initial capacity of the map * @param loadFactor the load factor. When the average number of references per table * exceeds this value resize will be attempted @@ -124,7 +124,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } /** - * Create a new {@link ConcurrentReferenceHashMap} instance. + * Create a new {@code ConcurrentReferenceHashMap} instance. * @param initialCapacity the initial capacity of the map * @param concurrencyLevel the expected number of threads that will concurrently write * to the map @@ -135,7 +135,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } /** - * Create a new {@link ConcurrentReferenceHashMap} instance. + * Create a new {@code ConcurrentReferenceHashMap} instance. * @param initialCapacity the initial capacity of the map * @param loadFactor the load factor. When the average number of references per table * exceeds this value resize will be attempted @@ -148,7 +148,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } /** - * Create a new {@link ConcurrentReferenceHashMap} instance. + * Create a new {@code ConcurrentReferenceHashMap} instance. * @param initialCapacity the initial capacity of the map * @param loadFactor the load factor. When the average number of references per table * exceeds this value resize will be attempted @@ -159,7 +159,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen public ConcurrentReferenceHashMap(int initialCapacity, float loadFactor, int concurrencyLevel, ReferenceType referenceType) { Assert.isTrue(concurrencyLevel > 0, "ConcurrencyLevel must be positive"); - Assert.isTrue(initialCapacity >= 0, "InitialCapactity must not be negative"); + Assert.isTrue(initialCapacity >= 0, "InitialCapacity must not be negative"); Assert.isTrue(loadFactor > 0f, "LoadFactor must be positive"); Assert.notNull(referenceType, "Reference type must not be null"); this.loadFactor = loadFactor; @@ -358,16 +358,16 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen } /** - * Calculate a shift value that can be to create a power-of-two value between + * Calculate a shift value that can be used to create a power-of-two value between * the specified maximum and minimum values. - * @param minimuxmValue the minimum value + * @param minimumValue the minimum value * @param maximumValue the maximum value * @return the calculated shift (use {@code 1 << shift} to obtain a value) */ - protected static int calculateShift(int minimuxmValue, int maximumValue) { + protected static int calculateShift(int minimumValue, int maximumValue) { int shift = 0; int value = 1; - while (value < minimuxmValue && value < minimuxmValue) { + while (value < minimumValue && value < minimumValue) { value <<= 1; shift++; } @@ -395,6 +395,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** * A single segment used to divide the map to allow better concurrent performance. */ + @SuppressWarnings("serial") protected final class Segment extends ReentrantLock { private final ReferenceManager referenceManager; @@ -621,7 +622,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** * A reference to an {@link Entry} contained in the map. Implementations are usually - * wrappers around specific java reference implementations (eg {@link SoftReference}). + * wrappers around specific Java reference implementations (e.g., {@link SoftReference}). */ protected static interface Reference { @@ -744,7 +745,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen protected T execute(Reference reference, Entry entry) { return null; } -} + } /** @@ -893,7 +894,7 @@ public class ConcurrentReferenceHashMap extends AbstractMap implemen /** - * The types of restructure that can be performed. + * The types of restructuring that can be performed. */ protected static enum Restructure { WHEN_NECESSARY, NEVER diff --git a/spring-core/src/test/java/org/springframework/util/ConcurrentReferenceHashMapTests.java b/spring-core/src/test/java/org/springframework/util/ConcurrentReferenceHashMapTests.java index a3d5867d853..5d35e6c0599 100644 --- a/spring-core/src/test/java/org/springframework/util/ConcurrentReferenceHashMapTests.java +++ b/spring-core/src/test/java/org/springframework/util/ConcurrentReferenceHashMapTests.java @@ -114,7 +114,7 @@ public class ConcurrentReferenceHashMapTests { public void shouldNeedNonNegativeInitialCapacity() throws Exception { new ConcurrentReferenceHashMap(0, 1); this.thrown.expect(IllegalArgumentException.class); - this.thrown.expectMessage("InitialCapactity must not be negative"); + this.thrown.expectMessage("InitialCapacity must not be negative"); new TestWeakConcurrentCache(-1, 1); }