jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sal...@apache.org
Subject svn commit: r1190377 - in /incubator/jena/Jena2/ARQ/trunk/src: main/java/org/openjena/atlas/iterator/IteratorCons.java test/java/org/openjena/atlas/iterator/TestIter.java
Date Fri, 28 Oct 2011 14:52:31 GMT
Author: sallen
Date: Fri Oct 28 14:52:31 2011
New Revision: 1190377

URL: http://svn.apache.org/viewvc?rev=1190377&view=rev
Log:
Fix for JENA-60 in ARQ.

Modified:
    incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/iterator/IteratorCons.java
    incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/atlas/iterator/TestIter.java

Modified: incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/iterator/IteratorCons.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/iterator/IteratorCons.java?rev=1190377&r1=1190376&r2=1190377&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/iterator/IteratorCons.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/main/java/org/openjena/atlas/iterator/IteratorCons.java
Fri Oct 28 14:52:31 2011
@@ -27,7 +27,8 @@ import java.util.NoSuchElementException 
 public class IteratorCons<T> implements Iterator<T>, Iterable<T>
 {
     private Iterator<? extends T> iter1 ;
-    private Iterator<? extends T> iter2 ;
+    private Iterator<? extends T> iter2 ;
+    private Iterator<? extends T> removeFrom ;
 
     public static <X> Iterator<X> create(Iterator<? extends X> iter1, Iterator<?
extends X> iter2)
     {
@@ -82,27 +83,27 @@ public class IteratorCons<T> implements 
     {
         if ( ! hasNext() )
             throw new NoSuchElementException("Iterator2.next") ;
-        if ( iter1 != null )
-            return iter1.next();
-        if ( iter2 != null )
-            return iter2.next();
+        if ( iter1 != null )
+        {
+            removeFrom = iter1 ;
+            return iter1.next();
+        }
+        if ( iter2 != null )
+        {
+            removeFrom = iter2 ;
+            return iter2.next();
+        }
         throw new Error("Iterator2.next") ;
     }
 
     @Override
     public void remove()
-    { 
-        if ( iter1 != null )
-        {
-            iter1.remove();
-            return ;
-        }
-        if ( iter2 != null )
-        {
-            iter2.remove();
-            return ;
-        }
-        throw new NoSuchElementException("Iterator2.remove") ;
+    {
+        if ( null == removeFrom )
+            throw new IllegalStateException("no calls to next() since last call to remove()")
;
+        
+        removeFrom.remove() ;
+        removeFrom = null ;
     }
 
     @Override

Modified: incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/atlas/iterator/TestIter.java
URL: http://svn.apache.org/viewvc/incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/atlas/iterator/TestIter.java?rev=1190377&r1=1190376&r2=1190377&view=diff
==============================================================================
--- incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/atlas/iterator/TestIter.java
(original)
+++ incubator/jena/Jena2/ARQ/trunk/src/test/java/org/openjena/atlas/iterator/TestIter.java
Fri Oct 28 14:52:31 2011
@@ -57,9 +57,93 @@ public class TestIter
         Iterator<String> iter = Iter.append(data1, data2) ;
         test(iter, "a", "x", "y", "z") ;
     }
-
+
+    @Test
+    public void append_4()
+    {
+        List<String> L = new ArrayList<String>(3);
+        L.add("a");
+        L.add("b");
+        L.add("c");
+        List<String> R = new ArrayList<String>(3);
+        R.add("d");
+        R.add("e");
+        R.add("f");
+        
+        
+        Iterator<String> LR = Iter.append(L, R) ;
+        
+        while (LR.hasNext())
+        {
+            String s = LR.next();
+            
+            if ("c".equals(s))
+            {
+                LR.hasNext();  // test for JENA-60
+                LR.remove();
+            }
+        }
+        
+        assertEquals("ab", Iter.asString(L, ""));
+        assertEquals("def", Iter.asString(R, ""));
+    }
+    
+    @Test
+    public void append_5()
+    {
+        List<String> L = new ArrayList<String>(3);
+        L.add("a");
+        L.add("b");
+        L.add("c");
+        List<String> R = new ArrayList<String>(3);
+        R.add("d");
+        R.add("e");
+        R.add("f");
+        
+        
+        Iterator<String> LR = Iter.append(L, R) ;
+        
+        while (LR.hasNext())
+        {
+            String s = LR.next();
+            
+            if ("d".equals(s))
+            {
+                LR.hasNext();  // test for JENA-60
+                LR.remove();
+            }
+        }
+        
+        assertEquals("abc", Iter.asString(L, ""));
+        assertEquals("ef", Iter.asString(R, ""));
+    }
     
     @Test
+    public void append_6()
+    {
+        List<String> L = new ArrayList<String>(3);
+        L.add("a");
+        L.add("b");
+        L.add("c");
+        List<String> R = new ArrayList<String>(3);
+        R.add("d");
+        R.add("e");
+        R.add("f");
+        
+        
+        Iterator<String> LR = Iter.append(L, R) ;
+        
+        while (LR.hasNext())
+        {
+            LR.next() ;
+        }
+        LR.remove() ;
+        
+        assertEquals("abc", Iter.asString(L, "")) ;
+        assertEquals("de", Iter.asString(R, "")) ;
+    }
+    
+    @Test
     public void asString_1() 
     {
         String x = Iter.asString(data0, "") ;



Mime
View raw message