pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From danielwil...@apache.org
Subject svn commit: r915500 - /pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSArray.java
Date Tue, 23 Feb 2010 20:26:07 GMT
Author: danielwilson
Date: Tue Feb 23 20:26:06 2010
New Revision: 915500

URL: http://svn.apache.org/viewvc?rev=915500&view=rev
Log:
Applied patch from PDFBOX-633

Modified:
    pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSArray.java

Modified: pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSArray.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSArray.java?rev=915500&r1=915499&r2=915500&view=diff
==============================================================================
--- pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSArray.java (original)
+++ pdfbox/trunk/src/main/java/org/apache/pdfbox/cos/COSArray.java Tue Feb 23 20:26:06 2010
@@ -366,7 +366,8 @@
      *
      * @param o The object to remove.
      *
-     * @return The object that was removed.
+     * @return <code>true</code> if the object was removed, <code>false</code>
+     *  otherwise
      */
     public boolean remove( COSBase o )
     {
@@ -374,6 +375,35 @@
     }
 
     /**
+     * This will remove an element from the array.
+     * This method will also remove a reference to the object.
+     * 
+     * @param o The object to remove.
+     * @return <code>true</code> if the object was removed, <code>false</code>
+     *  otherwise
+     */
+    public boolean removeObject(COSBase o)
+    {
+        boolean removed = this.remove(o);
+        if (!removed)
+        {
+            for (int i = 0; i < this.size(); i++)
+            {
+                COSBase entry = this.get(i);
+                if (entry instanceof COSObject)
+                {
+                    COSObject objEntry = (COSObject) entry;
+                    if (objEntry.getObject().equals(o))
+                    {
+                        return this.remove(entry);
+                    }
+                }
+            }
+        }
+        return removed;
+    }
+
+    /**
      * {@inheritDoc}
      */
     public String toString()
@@ -411,6 +441,36 @@
     }
 
     /**
+     * This will return the index of the entry or -1 if it is not found.
+     * This method will also find references to indirect objects.
+     * 
+     * @param object The object to search for.
+     * @return The index of the object or -1.
+     */
+    public int indexOfObject(COSBase object)
+    {
+        int retval = -1;
+        for (int i = 0; retval < 0 && i < this.size(); i++)
+        {
+            COSBase item = this.get(i);
+            if (item.equals(object))
+            {
+                retval = i;
+                break;
+            }
+            else if (item instanceof COSObject)
+            {
+                if (((COSObject) item).getObject().equals(object))
+                {
+                    retval = i;
+                    break;
+                }
+            }
+        }
+        return retval;
+    }
+
+    /**
      * This will add null values until the size of the array is at least
      * as large as the parameter.  If the array is already larger than the
      * parameter then nothing is done.



Mime
View raw message