You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jena.apache.org by an...@apache.org on 2012/12/03 23:08:14 UTC

svn commit: r1416696 - in /jena: branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/ branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/rdf/model/test/ trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/ trunk...

Author: andy
Date: Mon Dec  3 22:08:12 2012
New Revision: 1416696

URL: http://svn.apache.org/viewvc?rev=1416696&view=rev
Log:
JENA-360
Fix for copy of an empty list.

Modified:
    jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/RDFListImpl.java
    jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/rdf/model/test/TestList.java
    jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/RDFListImpl.java
    jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestList.java

Modified: jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/RDFListImpl.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/RDFListImpl.java?rev=1416696&r1=1416695&r2=1416696&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/RDFListImpl.java (original)
+++ jena/branches/jena-core-simplified/src/main/java/com/hp/hpl/jena/rdf/model/impl/RDFListImpl.java Mon Dec  3 22:08:12 2012
@@ -1117,25 +1117,33 @@ public class RDFListImpl
         Property tail = listRest();
         Resource cellType = listType();
         
-        while (i.hasNext()){
-            // create a list cell to hold the next value from the existing list
-            Resource cell = getModel().createResource( cellType );
-            cell.addProperty( head, i.next() );
-                
-            // point the previous list cell to this one
-            if (list != null) {
-                list.addProperty( tail, cell ); 
-            }
-            else {
-                // must be the first cell we're adding
-                start = cell;
-            }
-                
-            list = cell;
+        if (i.hasNext())
+        {
+	        while (i.hasNext()){
+	            // create a list cell to hold the next value from the existing list
+	            Resource cell = getModel().createResource( cellType );
+	            cell.addProperty( head, i.next() );
+	                
+	            // point the previous list cell to this one
+	            if (list != null) {
+	                list.addProperty( tail, cell ); 
+	            }
+	            else {
+	                // must be the first cell we're adding
+	                start = cell;
+	            }
+	                
+	            list = cell;
+	        }
+	            
+	        // finally close the list
+	        list.addProperty( tail, listNil() );
+        }
+        else
+        {
+        	// create an empty list
+        	start = getModel().createList();
         }
-            
-        // finally close the list
-        list.addProperty( tail, listNil() );
             
         return start.as( listAbstractionClass() );
     }

Modified: jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/rdf/model/test/TestList.java
URL: http://svn.apache.org/viewvc/jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/rdf/model/test/TestList.java?rev=1416696&r1=1416695&r2=1416696&view=diff
==============================================================================
--- jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/rdf/model/test/TestList.java (original)
+++ jena/branches/jena-core-simplified/src/test/java/com/hp/hpl/jena/rdf/model/test/TestList.java Mon Dec  3 22:08:12 2012
@@ -106,7 +106,7 @@ public class TestList
         s.addTest( new ListEqualsTest() );
         s.addTest( new ListSubclassTest() );
         s.addTest( new UserDefinedListTest() );
-        
+        s.addTest( new CopyTest() );
         return s;
     }
     
@@ -677,6 +677,19 @@ public class TestList
        }
     }
     
+    protected static class CopyTest extends ListTest {
+        public CopyTest() {super("CopyTest");}
+        
+        @Override
+        public void runTest() {
+            Model m = ModelFactory.createDefaultModel();
+            // check for empty copy error (JENA-360)
+            RDFList list = m.createList().copy();
+            assertEquals( "Should be a 0 length list", 0, list.size() );
+  
+       }
+    }
+    
     
     protected static class ApplyTest extends ListTest {
         public ApplyTest() {super("ApplyTest");}

Modified: jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/RDFListImpl.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/RDFListImpl.java?rev=1416696&r1=1416695&r2=1416696&view=diff
==============================================================================
--- jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/RDFListImpl.java (original)
+++ jena/trunk/jena-core/src/main/java/com/hp/hpl/jena/rdf/model/impl/RDFListImpl.java Mon Dec  3 22:08:12 2012
@@ -1117,25 +1117,33 @@ public class RDFListImpl
         Property tail = listRest();
         Resource cellType = listType();
         
-        while (i.hasNext()){
-            // create a list cell to hold the next value from the existing list
-            Resource cell = getModel().createResource( cellType );
-            cell.addProperty( head, i.next() );
-                
-            // point the previous list cell to this one
-            if (list != null) {
-                list.addProperty( tail, cell ); 
-            }
-            else {
-                // must be the first cell we're adding
-                start = cell;
-            }
-                
-            list = cell;
+        if (i.hasNext())
+        {
+	        while (i.hasNext()){
+	            // create a list cell to hold the next value from the existing list
+	            Resource cell = getModel().createResource( cellType );
+	            cell.addProperty( head, i.next() );
+	                
+	            // point the previous list cell to this one
+	            if (list != null) {
+	                list.addProperty( tail, cell ); 
+	            }
+	            else {
+	                // must be the first cell we're adding
+	                start = cell;
+	            }
+	                
+	            list = cell;
+	        }
+	            
+	        // finally close the list
+	        list.addProperty( tail, listNil() );
+        }
+        else
+        {
+        	// create an empty list
+        	start = getModel().createList();
         }
-            
-        // finally close the list
-        list.addProperty( tail, listNil() );
             
         return start.as( listAbstractionClass() );
     }

Modified: jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestList.java
URL: http://svn.apache.org/viewvc/jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestList.java?rev=1416696&r1=1416695&r2=1416696&view=diff
==============================================================================
--- jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestList.java (original)
+++ jena/trunk/jena-core/src/test/java/com/hp/hpl/jena/rdf/model/test/TestList.java Mon Dec  3 22:08:12 2012
@@ -106,7 +106,7 @@ public class TestList
         s.addTest( new ListEqualsTest() );
         s.addTest( new ListSubclassTest() );
         s.addTest( new UserDefinedListTest() );
-        
+        s.addTest( new CopyTest() );
         return s;
     }
     
@@ -677,6 +677,19 @@ public class TestList
        }
     }
     
+    protected static class CopyTest extends ListTest {
+        public CopyTest() {super("CopyTest");}
+        
+        @Override
+        public void runTest() {
+            Model m = ModelFactory.createDefaultModel();
+            // check for empty copy error (JENA-360)
+            RDFList list = m.createList().copy();
+            assertEquals( "Should be a 0 length list", 0, list.size() );
+  
+       }
+    }
+    
     
     protected static class ApplyTest extends ListTest {
         public ApplyTest() {super("ApplyTest");}