commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From scolebou...@apache.org
Subject svn commit: r219330 - in /jakarta/commons/proper/collections/trunk: RELEASE-NOTES.html src/java/org/apache/commons/collections/list/CursorableLinkedList.java src/test/org/apache/commons/collections/list/TestCursorableLinkedList.java
Date Sat, 16 Jul 2005 14:19:43 GMT
Author: scolebourne
Date: Sat Jul 16 07:19:42 2005
New Revision: 219330

URL: http://svn.apache.org/viewcvs?rev=219330&view=rev
Log:
Fix CursorableLinkedList iterator remove/set not throwing IllegalStateException after next-previous-removeByIndex
bug 35766

Modified:
    jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html
    jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/CursorableLinkedList.java
    jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestCursorableLinkedList.java

Modified: jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html?rev=219330&r1=219329&r2=219330&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html (original)
+++ jakarta/commons/proper/collections/trunk/RELEASE-NOTES.html Sat Jul 16 07:19:42 2005
@@ -74,6 +74,7 @@
 <ul>
 <li>FastArrayList - Fix iterators and views to work better in multithreaded environments</li>
 <li>FastArrayList - Fix iterator remove where ConcurrentModificationException not as
expected [34690]</li>
+<li>CursorableLinkedList (list subpackage) - Fix iterator remove/set not throwing IllegalStateException
after next-previous-removeByIndex [35766]</li>
 <li>SetUniqueList.set(int,Object) - Destroyed set status in certain circumstances [33294]</li>
 <li>AbstractLinkedMap.init() - Now calls createEntry() to create the map entry object
[33706]</li>
 <li>AbstractHashedMap deserialization - Fix to prevent doubling of internal data array
[34265]</li>

Modified: jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/CursorableLinkedList.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/CursorableLinkedList.java?rev=219330&r1=219329&r2=219330&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/CursorableLinkedList.java
(original)
+++ jakarta/commons/proper/collections/trunk/src/java/org/apache/commons/collections/list/CursorableLinkedList.java
Sat Jul 16 07:19:42 2005
@@ -445,9 +445,17 @@
          * @param node  the node that was removed
          */
         protected void nodeRemoved(Node node) {
-            if (node == next) {
+            if (node == next && node == current) {
+                // state where next() followed by previous()
+                next = node.next;
+                current = null;
+            } else if (node == next) {
+                // state where next() not followed by previous()
+                // and we are matching next node
                 next = node.next;
             } else if (node == current) {
+                // state where next() not followed by previous()
+                // and we are matching current (last returned) node
                 current = null;
                 nextIndex--;
             } else {

Modified: jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestCursorableLinkedList.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestCursorableLinkedList.java?rev=219330&r1=219329&r2=219330&view=diff
==============================================================================
--- jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestCursorableLinkedList.java
(original)
+++ jakarta/commons/proper/collections/trunk/src/test/org/apache/commons/collections/list/TestCursorableLinkedList.java
Sat Jul 16 07:19:42 2005
@@ -444,7 +444,78 @@
         assertEquals(1, c1.nextIndex());
         assertEquals("0", c1.next());
     }
-    
+
+    //-----------------------------------------------------------------------
+    public void testInternalState_CursorNextNextPreviousRemoveIndex1ByList() {
+        list.add("A");
+        list.add("B");
+        list.add("C");
+
+        CursorableLinkedList.Cursor c1 = list.cursor();
+        assertEquals("A", c1.next());
+        assertEquals("B", c1.next());
+        assertEquals("B", c1.previous());
+        
+        assertEquals("B", list.remove(1));
+        
+        assertEquals(true, c1.nextIndexValid);
+        assertEquals(1, c1.nextIndex);
+        assertEquals(null, c1.current);
+        assertEquals("C", c1.next.value);
+    }
+
+    public void testInternalState_CursorNextRemoveIndex1ByList() {
+        list.add("A");
+        list.add("B");
+        list.add("C");
+
+        CursorableLinkedList.Cursor c1 = list.cursor();
+        assertEquals("A", c1.next());
+        
+        assertEquals("B", list.remove(1));
+        
+        assertEquals(true, c1.nextIndexValid);
+        assertEquals(1, c1.nextIndex);
+        assertEquals("A", c1.current.value);
+        assertEquals("C", c1.next.value);
+    }
+
+    public void testInternalState_CursorNextNextRemoveIndex1ByList() {
+        list.add("A");
+        list.add("B");
+        list.add("C");
+
+        CursorableLinkedList.Cursor c1 = list.cursor();
+        assertEquals("A", c1.next());
+        assertEquals("B", c1.next());
+        
+        assertEquals("B", list.remove(1));
+        
+        assertEquals(true, c1.nextIndexValid);
+        assertEquals(1, c1.nextIndex);
+        assertEquals(null, c1.current);
+        assertEquals("C", c1.next.value);
+    }
+
+    public void testInternalState_CursorNextNextNextRemoveIndex1ByList() {
+        list.add("A");
+        list.add("B");
+        list.add("C");
+        list.add("D");
+
+        CursorableLinkedList.Cursor c1 = list.cursor();
+        assertEquals("A", c1.next());
+        assertEquals("B", c1.next());
+        assertEquals("C", c1.next());
+        
+        assertEquals("B", list.remove(1));
+        
+        assertEquals(false, c1.nextIndexValid);
+        assertEquals("C", c1.current.value);
+        assertEquals("D", c1.next.value);
+    }
+
+    //-----------------------------------------------------------------------
     public void testEqualsAndHashCode() {
         assertTrue(list.equals(list));
         assertEquals(list.hashCode(),list.hashCode());



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message