[Arakhnę-Dev] [86] - Add could of released objects in listener's parameter.

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


Revision: 86
Author:   galland
Date:     2009-11-03 15:44:09 +0100 (Tue, 03 Nov 2009)
Log Message:
-----------
- Add could of released objects in listener's parameter.

Modified Paths:
--------------
    trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/ReferenceListener.java
    trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/WeakArrayList.java
    trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakArrayListTest.java

Modified: trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/ReferenceListener.java
===================================================================
--- trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/ReferenceListener.java	2009-11-03 14:27:47 UTC (rev 85)
+++ trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/ReferenceListener.java	2009-11-03 14:44:09 UTC (rev 86)
@@ -35,7 +35,9 @@
 	 * <p>
 	 * No reference is given to avoid strong referencing of the released objects
 	 * inside the listener's source code.
+	 * 
+	 * @param released is the count of released objects.
 	 */
-	public void referenceReleased();
+	public void referenceReleased(int released);
 	
 }

Modified: trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/WeakArrayList.java
===================================================================
--- trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/WeakArrayList.java	2009-11-03 14:27:47 UTC (rev 85)
+++ trunk/arakhneRefs/src/main/java/org/arakhne/util/ref/WeakArrayList.java	2009-11-03 14:44:09 UTC (rev 86)
@@ -256,10 +256,12 @@
 		while (this.queue.poll()!=null) {
 			this.enquedElement = true;
 		}
+
+		int oldSize = this.size;
+		this.size = j;
 		
-		if (this.size!=j) {
-			this.size = j;
-			fireReferenceRelease();
+		if (j<oldSize) {
+			fireReferenceRelease(oldSize - j);
 		}
 
 		return this.size;
@@ -386,12 +388,14 @@
     
     /**
      * Fire the reference release event.
+     * 
+     * @param released is the count of released objects.
      */
-    protected void fireReferenceRelease() {
+    protected void fireReferenceRelease(int released) {
 		List<ReferenceListener> list = this.listeners;
     	if (list!=null && !list.isEmpty()) {
     		for(ReferenceListener listener : list) {
-    			listener.referenceReleased();
+    			listener.referenceReleased(released);
     		}
     	}
     }

Modified: trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakArrayListTest.java
===================================================================
--- trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakArrayListTest.java	2009-11-03 14:27:47 UTC (rev 85)
+++ trunk/arakhneRefs/src/test/java/org/arakhne/util/ref/WeakArrayListTest.java	2009-11-03 14:44:09 UTC (rev 86)
@@ -878,7 +878,7 @@
 		collect(list);
 		
 		assertTrue(list.isEmpty());
-		assertEquals(1, listener.count);
+		assertEquals(count, listener.count);
 		
 	}
 	
@@ -891,8 +891,8 @@
 		}
 
 		@Override
-		public void referenceReleased() {
-			this.count++;
+		public void referenceReleased(int released) {
+			this.count += released;
 		}
 		
 	}


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