pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From msahy...@apache.org
Subject svn commit: r1651719 - in /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form: FieldUtils.java PDAcroForm.java PDButton.java PDCheckbox.java PDChoice.java PDFieldTreeNode.java PDRadioButton.java
Date Wed, 14 Jan 2015 16:16:44 GMT
Author: msahyoun
Date: Wed Jan 14 16:16:44 2015
New Revision: 1651719

URL: http://svn.apache.org/r1651719
Log:
PDFBOX-2516 code cleanup

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/FieldUtils.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/FieldUtils.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/FieldUtils.java?rev=1651719&r1=1651718&r2=1651719&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/FieldUtils.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/FieldUtils.java
Wed Jan 14 16:16:44 2015
@@ -16,6 +16,7 @@
  */
 package org.apache.pdfbox.pdmodel.interactive.form;
 
+import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
@@ -66,8 +67,11 @@ public final class FieldUtils
     /**
      * Comparator to sort KeyValue by key.
      */
-    static class KeyValueKeyComparator implements Comparator<KeyValue>
+    static class KeyValueKeyComparator implements Serializable, Comparator<KeyValue>
     {
+
+        private static final long serialVersionUID = 6715364290007167694L;
+
         @Override
         public int compare(KeyValue o1, KeyValue o2)
         {
@@ -78,8 +82,11 @@ public final class FieldUtils
     /**
      * Comparator to sort KeyValue by value.
      */
-    static class KeyValueValueComparator implements Comparator<KeyValue>
+    static class KeyValueValueComparator implements Serializable, Comparator<KeyValue>
     {
+
+        private static final long serialVersionUID = -3984095679894798265L;
+
         @Override
         public int compare(KeyValue o1, KeyValue o2)
         {
@@ -101,9 +108,9 @@ public final class FieldUtils
      * @param value the value elements
      * @return a sorted list of KeyValue elements.
      */
-    static final List<KeyValue> toKeyValueList(List<String> key, List<String>
value)
+    static List<KeyValue> toKeyValueList(List<String> key, List<String>
value)
     {
-        ArrayList<KeyValue> list = new ArrayList<KeyValue>();
+        List<KeyValue> list = new ArrayList<KeyValue>();
         for(int i =0; i<key.size(); i++)
         {
             list.add(new FieldUtils.KeyValue(key.get(i),value.get(i)));
@@ -116,7 +123,7 @@ public final class FieldUtils
      * 
      * @param pairs a list of KeyValue elements
      */
-    static final void sortByValue(List<KeyValue> pairs)
+    static void sortByValue(List<KeyValue> pairs)
     {
         Collections.sort(pairs, new FieldUtils.KeyValueValueComparator());
     }
@@ -126,7 +133,7 @@ public final class FieldUtils
      * 
      * @param pairs a list of KeyValue elements
      */
-    static final void sortByKey(List<KeyValue> pairs)
+    static void sortByKey(List<KeyValue> pairs)
     {
         Collections.sort(pairs, new FieldUtils.KeyValueKeyComparator());
     }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java?rev=1651719&r1=1651718&r2=1651719&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDAcroForm.java
Wed Jan 14 16:16:44 2015
@@ -33,6 +33,7 @@ import org.apache.pdfbox.pdmodel.fdf.FDF
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -145,7 +146,7 @@ public final class PDAcroForm implements
             addFieldAndChildren( docField, fdfFields );
         }
         fdfDict.setID( document.getDocument().getDocumentID() );
-        if( fdfFields.size() > 0 )
+        if( !fdfFields.isEmpty() )
         {
             fdfDict.setFields( fdfFields );
         }
@@ -166,12 +167,12 @@ public final class PDAcroForm implements
             {
                 addFieldAndChildren((PDFieldTreeNode) kid, childFDFFields);
             }
-            if( childFDFFields.size() > 0 )
+            if( !childFDFFields.isEmpty() )
             {
                 fdfField.setKids( childFDFFields );
             }
         }
-        if( fieldValue != null || childFDFFields.size() > 0 )
+        if( fieldValue != null || !childFDFFields.isEmpty() )
         {
             fdfFields.add( fdfField );
         }
@@ -195,7 +196,7 @@ public final class PDAcroForm implements
         COSArray cosFields = (COSArray) acroForm.getDictionaryObject(COSName.FIELDS);
         if( cosFields == null )
         {
-            return null;
+            return Collections.<PDFieldTreeNode>emptyList();
         }
         List<PDFieldTreeNode> pdFields = new ArrayList<PDFieldTreeNode>();
         for (int i = 0; i < cosFields.size(); i++)

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java?rev=1651719&r1=1651718&r2=1651719&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDButton.java
Wed Jan 14 16:16:44 2015
@@ -112,7 +112,7 @@ public abstract class PDButton extends P
      */
     public void setOptions( List<String> options )
     {
-        if (options == null || options.size() == 0)
+        if (options == null || options.isEmpty())
         {
             getDictionary().removeItem(COSName.OPT);
         }

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java?rev=1651719&r1=1651718&r2=1651719&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDCheckbox.java
Wed Jan 14 16:16:44 2015
@@ -80,7 +80,7 @@ public final class PDCheckbox extends PD
             // Ignoring as that will also mean that the field is not checked.
             // Setting the value explicitly as Code Analysis (Sonar) doesn't like
             // empty catch blocks.
-            fieldValue = null;
+            return false;
         }
         COSName radioValue = (COSName)getDictionary().getDictionaryObject( COSName.AS );
         if( radioValue != null && fieldValue != null && radioValue.getName().equals(
onValue ) )

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java?rev=1651719&r1=1651718&r2=1651719&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDChoice.java
Wed Jan 14 16:16:44 2015
@@ -112,8 +112,7 @@ public abstract class PDChoice extends P
                     exportValues.add(displayValue.getString());
                 }
                 return exportValues;
-            }
-            
+            }            
         }
         return Collections.<String>emptyList();
     }
@@ -135,7 +134,7 @@ public abstract class PDChoice extends P
      */
     public void setOptions(List<String> displayValues)
     {
-        if (displayValues != null && displayValues.size() > 0)
+        if (displayValues != null && !displayValues.isEmpty())
         {
             if (isSort())
             {
@@ -169,11 +168,7 @@ public abstract class PDChoice extends P
      */
     public void setOptions(List<String> exportValues, List<String> displayValues)
     {
-        if (exportValues == null || displayValues == null || exportValues.size() == 0 ||
displayValues.size() == 0)
-        {
-            getDictionary().removeItem(COSName.OPT);
-        }
-        else if (exportValues != null && displayValues != null && exportValues.size()
> 0 && displayValues.size() > 0) 
+        if (exportValues != null && displayValues != null && !exportValues.isEmpty()
&& !displayValues.isEmpty()) 
         {
             if (exportValues.size() != displayValues.size())
             {
@@ -200,6 +195,10 @@ public abstract class PDChoice extends P
                 getDictionary().setItem(COSName.OPT, options);
             }
         }
+        else
+        {
+            getDictionary().removeItem(COSName.OPT);
+        }      
     }
 
     /**

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java?rev=1651719&r1=1651718&r2=1651719&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDFieldTreeNode.java
Wed Jan 14 16:16:44 2015
@@ -518,7 +518,7 @@ public abstract class PDFieldTreeNode im
         {
             retval = new PDAnnotationWidget(getDictionary());
         }
-        else if (kids.size() > 0)
+        else if (!kids.isEmpty())
         {
             Object firstKid = kids.get(0);
             if (firstKid instanceof PDAnnotationWidget)

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java?rev=1651719&r1=1651718&r2=1651719&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/interactive/form/PDRadioButton.java
Wed Jan 14 16:16:44 2015
@@ -142,7 +142,7 @@ public final class PDRadioButton extends
     public String getExportValue() throws IOException
     {
         List<String> options = getOptions();
-        if (options.size() == 0)
+        if (options.isEmpty())
         {
             return getValue();
         }



Mime
View raw message