pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1868375 - in /pdfbox/branches/2.0/pdfbox/src: main/java/org/apache/pdfbox/pdmodel/common/COSArrayList.java test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java
Date Sat, 12 Oct 2019 22:15:24 GMT
Author: msahyoun
Date: Sat Oct 12 22:15:24 2019
New Revision: 1868375

URL: http://svn.apache.org/viewvc?rev=1868375&view=rev
Log:
PDFBOX-4669: fix removing when filtered by object; add test

Modified:
    pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSArrayList.java
    pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java

Modified: pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSArrayList.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSArrayList.java?rev=1868375&r1=1868374&r2=1868375&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSArrayList.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/COSArrayList.java
Sat Oct 12 22:15:24 2019
@@ -204,8 +204,12 @@ public class COSArrayList<E> implements
         int index = actual.indexOf( o );
         if( index >= 0 )
         {
-            actual.remove( index );
-            array.remove( index );
+            Object removed = actual.remove( index );
+
+            if (removed instanceof COSObjectable) {
+                COSBase cosBase = ((COSObjectable) removed).getCOSObject();
+                retval = array.remove(cosBase);
+            }
         }
         else
         {

Modified: pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java?rev=1868375&r1=1868374&r2=1868375&view=diff
==============================================================================
--- pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java
(original)
+++ pdfbox/branches/2.0/pdfbox/src/test/java/org/apache/pdfbox/pdmodel/common/COSArrayListTest.java
Sat Oct 12 22:15:24 2019
@@ -194,7 +194,7 @@ public class COSArrayListTest {
     }
 
     @Test
-    public void removeFromFilteredListByIndex() throws Exception
+    public void removeFromFilteredListByObject() throws Exception
     {
         // retrieve all annotations from page but the link annotation
         // which is 2nd in list - see above setup
@@ -216,18 +216,16 @@ public class COSArrayListTest {
 
         // remove aCircle annotation
         int positionToRemove = 1;
-        PDAnnotation removedAnnot = cosArrayList.remove(positionToRemove);
-        assertTrue("We should have removed the circle annotation", removedAnnot.getSubtype().equals(PDAnnotationSquareCircle.SUB_TYPE_CIRCLE));
+        PDAnnotation toBeRemoved = cosArrayList.get(positionToRemove);
+        assertTrue("We should remove the circle annotation", toBeRemoved.getSubtype().equals(PDAnnotationSquareCircle.SUB_TYPE_CIRCLE));
+        cosArrayList.remove(toBeRemoved);
 
         assertTrue("List size shall be 2", cosArrayList.size() == 1);
         assertTrue("COSArray size shall be 2", underlyingCOSArray.size() == 2);
         assertTrue("Backed COSArray size shall be 2", cosArrayList.toList().size() == 2);
 
-        assertTrue("Removed annotation shall no longer appear in COSArrayList", cosArrayList.indexOf(removedAnnot)
== -1);
-        
-        // TODO: fix removing an item if list is filtered and enable the following line in
test
-        // assertTrue("Removed annotation shall no longer appear in underlying COSArray",
underlyingCOSArray.indexOf(removedAnnot.getCOSObject()) == -1);
-        // assertTrue("Removed annotation shall no longer appear in backed COSArray", cosArrayList.toList().indexOf(removedAnnot.getCOSObject())
== -1);
-
+        assertTrue("Removed annotation shall no longer appear in COSArrayList", cosArrayList.indexOf(toBeRemoved)
== -1);
+        assertTrue("Removed annotation shall no longer appear in underlying COSArray", underlyingCOSArray.indexOf(toBeRemoved.getCOSObject())
== -1);
+        assertTrue("Removed annotation shall no longer appear in backed COSArray", cosArrayList.toList().indexOf(toBeRemoved.getCOSObject())
== -1);
     }
 }
\ No newline at end of file



Mime
View raw message