You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2014/12/21 16:53:01 UTC

svn commit: r1647160 - /pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/schema/XMPSchema.java

Author: tilman
Date: Sun Dec 21 15:53:00 2014
New Revision: 1647160

URL: http://svn.apache.org/r1647160
Log:
PDFBOX-2576: split up long method into smaller ones; remove variable (alreadyPresent) that is always false

Modified:
    pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/schema/XMPSchema.java

Modified: pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/schema/XMPSchema.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/schema/XMPSchema.java?rev=1647160&r1=1647159&r2=1647160&view=diff
==============================================================================
--- pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/schema/XMPSchema.java (original)
+++ pdfbox/trunk/xmpbox/src/main/java/org/apache/xmpbox/schema/XMPSchema.java Sun Dec 21 15:53:00 2014
@@ -1213,41 +1213,16 @@ public class XMPSchema extends AbstractS
                 {
                     analyzedPropQualifiedName = prop.getPropertyName();
                     Iterator<AbstractField> itActualEmbeddedProperties = getAllProperties().iterator();
-                    AbstractField tmpEmbeddedProperty;
-
-                    Iterator<AbstractField> itNewValues;
-                    TextType tmpNewValue;
-
-                    Iterator<AbstractField> itOldValues;
-                    TextType tmpOldValue;
-
-                    boolean alreadyPresent = false;
-
                     while (itActualEmbeddedProperties.hasNext())
                     {
-                        tmpEmbeddedProperty = itActualEmbeddedProperties.next();
+                        AbstractField tmpEmbeddedProperty = itActualEmbeddedProperties.next();
                         if (tmpEmbeddedProperty instanceof ArrayProperty && 
                                 tmpEmbeddedProperty.getPropertyName().equals(analyzedPropQualifiedName))
                         {
-                            itNewValues = ((ArrayProperty) prop).getContainer().getAllProperties().iterator();
-                            // Merge a complex property
-                            while (itNewValues.hasNext())
+                            Iterator<AbstractField> itNewValues = ((ArrayProperty) prop).getContainer().getAllProperties().iterator();
+                            if (mergeComplexProperty(itNewValues, (ArrayProperty) tmpEmbeddedProperty)) 
                             {
-                                tmpNewValue = (TextType) itNewValues.next();
-                                itOldValues = ((ArrayProperty) tmpEmbeddedProperty).getContainer()
-                                        .getAllProperties().iterator();
-                                while (itOldValues.hasNext() && !alreadyPresent)
-                                {
-                                    tmpOldValue = (TextType) itOldValues.next();
-                                    if (tmpOldValue.getStringValue().equals(tmpNewValue.getStringValue()))
-                                    {
-                                        return;
-                                    }
-                                }
-                                if (!alreadyPresent)
-                                {
-                                    ((ArrayProperty) tmpEmbeddedProperty).getContainer().addProperty(tmpNewValue);
-                                }
+                                return;
                             }
                         }
                     }
@@ -1260,6 +1235,25 @@ public class XMPSchema extends AbstractS
         }
     }
 
+    private boolean mergeComplexProperty(Iterator<AbstractField> itNewValues, ArrayProperty arrayProperty)
+    {
+        while (itNewValues.hasNext())
+        {
+            TextType tmpNewValue = (TextType) itNewValues.next();
+            Iterator<AbstractField> itOldValues = arrayProperty.getContainer().getAllProperties().iterator();
+            while (itOldValues.hasNext())
+            {
+                TextType tmpOldValue = (TextType) itOldValues.next();
+                if (tmpOldValue.getStringValue().equals(tmpNewValue.getStringValue()))
+                {
+                    return true;
+                }
+            }
+            arrayProperty.getContainer().addProperty(tmpNewValue);
+        }
+        return false;
+    }
+
     /**
      * Get an AbstractField list corresponding to the content of an array Return null if the property is unknown
      *