[Arakhnę-Dev] [320] * Deprecate WeakValueMap and SoftValueMap.

[ Thread Index | Date Index | More arakhne.org/dev Archives ]


Revision: 320
Author:   galland
Date:     2011-12-17 13:29:18 +0100 (Sat, 17 Dec 2011)
Log Message:
-----------
* Deprecate WeakValueMap and SoftValueMap.

Modified Paths:
--------------
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/AbstractMapTestCase.java
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/AbstractReferencableValueMapTestCase.java
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/PhantomValueHashMapTest.java
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/PhantomValueTreeMapTest.java
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/SoftValueHashMapTest.java
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/SoftValueTreeMapTest.java
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakValueHashMapTest.java
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakValueTreeMapTest.java

Modified: trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/AbstractMapTestCase.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/AbstractMapTestCase.java	2011-12-17 11:43:54 UTC (rev 319)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/AbstractMapTestCase.java	2011-12-17 12:29:18 UTC (rev 320)
@@ -38,7 +38,9 @@
  */
 public abstract class AbstractMapTestCase<K,V> extends AbstractTestCase {
 
-	private final Random RANDOM = new Random();
+	/** Random number generator.
+	 */
+	protected final Random RANDOM = new Random();
 	
 	/**
 	 */
@@ -108,7 +110,13 @@
 		super.tearDown();
 	}
 	
-	private static <KK> KK key(Map<KK,?> map, int index) {
+	/** Replies the key at the given index.
+	 * 
+	 * @param map
+	 * @param index
+	 * @return the key
+	 */
+	public static <KK> KK key(Map<KK,?> map, int index) {
 		int i = 0; 
 		for(KK key : map.keySet()) {
 			if (i==index) return key;
@@ -117,7 +125,13 @@
 		throw new IndexOutOfBoundsException();
 	}
 	
-	private static <VV> VV value(Map<?,VV> map, int index) {
+	/** Replies the value at the given index.
+	 * 
+	 * @param map
+	 * @param index
+	 * @return the vlaue
+	 */
+	public static <VV> VV value(Map<?,VV> map, int index) {
 		int i = 0; 
 		for(VV value : map.values()) {
 			if (i==index) return value;

Modified: trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/AbstractReferencableValueMapTestCase.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/AbstractReferencableValueMapTestCase.java	2011-12-17 11:43:54 UTC (rev 319)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/AbstractReferencableValueMapTestCase.java	2011-12-17 12:29:18 UTC (rev 320)
@@ -19,6 +19,9 @@
  */
 package org.arakhne.util.ref;
 
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
 import java.util.UUID;
 
 /**
@@ -29,10 +32,47 @@
  */
 public abstract class AbstractReferencableValueMapTestCase extends AbstractMapTestCase<String,String> {
 
+	/** Force the garbarge collector to run.
+	 */
+	public static void freeMemory() {
+		for(int i=0; i<6; ++i) {
+			System.gc();
+		}
+	}
+	
+	private final boolean looseReferences;
+	
+	private Set<String> loosedKeys;
+	
 	/**
+	 * @param looseReferences
+	 */
+	public AbstractReferencableValueMapTestCase(boolean looseReferences) {
+		this.looseReferences = looseReferences;
+	}
+	
+	/**
 	 * {@inheritDoc}
 	 */
 	@Override
+	public void setUp() throws Exception {
+		super.setUp();
+		this.loosedKeys = new TreeSet<String>();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	public void tearDown() throws Exception {
+		this.loosedKeys = null;
+		super.tearDown();
+	}
+	
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
 	protected String createKeyInstance(String prefix) {
 		return prefix+UUID.randomUUID().toString();
 	}
@@ -45,4 +85,22 @@
 		return prefix+UUID.randomUUID().toString();
 	}
 
+	/**
+	 * {@inheritDoc}
+	 */
+	@Override
+	protected void initMapWith(Map<String, String> toAdd) {
+		super.initMapWith(toAdd);
+		if (this.looseReferences) {
+			int loosedCount = this.RANDOM.nextInt(this.reference.size())+5;
+			for(int i=0; !this.reference.isEmpty() && i<loosedCount; ++i) {
+				int idx = this.RANDOM.nextInt(this.reference.size());
+				String key = key(this.reference, idx);
+				this.loosedKeys.add(key);
+				this.reference.remove(key);
+			}
+			freeMemory();
+		}
+	}
+	
 }

Modified: trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/PhantomValueHashMapTest.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/PhantomValueHashMapTest.java	2011-12-17 11:43:54 UTC (rev 319)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/PhantomValueHashMapTest.java	2011-12-17 12:29:18 UTC (rev 320)
@@ -30,6 +30,12 @@
 public class PhantomValueHashMapTest extends AbstractReferencableValueMapTestCase {
 
 	/**
+	 */
+	public PhantomValueHashMapTest() {
+		super(false);
+	}
+	
+	/**
 	 * {@inheritDoc}
 	 */
 	@Override

Modified: trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/PhantomValueTreeMapTest.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/PhantomValueTreeMapTest.java	2011-12-17 11:43:54 UTC (rev 319)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/PhantomValueTreeMapTest.java	2011-12-17 12:29:18 UTC (rev 320)
@@ -30,6 +30,12 @@
 public class PhantomValueTreeMapTest extends AbstractReferencableValueMapTestCase {
 
 	/**
+	 */
+	public PhantomValueTreeMapTest() {
+		super(false);
+	}
+
+	/**
 	 * {@inheritDoc}
 	 */
 	@Override

Modified: trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/SoftValueHashMapTest.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/SoftValueHashMapTest.java	2011-12-17 11:43:54 UTC (rev 319)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/SoftValueHashMapTest.java	2011-12-17 12:29:18 UTC (rev 320)
@@ -30,6 +30,12 @@
 public class SoftValueHashMapTest extends AbstractReferencableValueMapTestCase {
 
 	/**
+	 */
+	public SoftValueHashMapTest() {
+		super(false);
+	}
+
+	/**
 	 * {@inheritDoc}
 	 */
 	@Override

Modified: trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/SoftValueTreeMapTest.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/SoftValueTreeMapTest.java	2011-12-17 11:43:54 UTC (rev 319)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/SoftValueTreeMapTest.java	2011-12-17 12:29:18 UTC (rev 320)
@@ -30,6 +30,12 @@
 public class SoftValueTreeMapTest extends AbstractReferencableValueMapTestCase {
 
 	/**
+	 */
+	public SoftValueTreeMapTest() {
+		super(false);
+	}
+
+	/**
 	 * {@inheritDoc}
 	 */
 	@Override

Modified: trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakValueHashMapTest.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakValueHashMapTest.java	2011-12-17 11:43:54 UTC (rev 319)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakValueHashMapTest.java	2011-12-17 12:29:18 UTC (rev 320)
@@ -30,6 +30,12 @@
 public class WeakValueHashMapTest extends AbstractReferencableValueMapTestCase {
 
 	/**
+	 */
+	public WeakValueHashMapTest() {
+		super(false);
+	}
+
+	/**
 	 * {@inheritDoc}
 	 */
 	@Override

Modified: trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakValueTreeMapTest.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakValueTreeMapTest.java	2011-12-17 11:43:54 UTC (rev 319)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakValueTreeMapTest.java	2011-12-17 12:29:18 UTC (rev 320)
@@ -30,6 +30,12 @@
 public class WeakValueTreeMapTest extends AbstractReferencableValueMapTestCase {
 
 	/**
+	 */
+	public WeakValueTreeMapTest() {
+		super(false);
+	}
+
+	/**
 	 * {@inheritDoc}
 	 */
 	@Override


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/