pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From til...@apache.org
Subject svn commit: r1763796 - /pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java
Date Fri, 07 Oct 2016 16:23:09 GMT
Author: tilman
Date: Fri Oct  7 16:23:08 2016
New Revision: 1763796

URL: http://svn.apache.org/viewvc?rev=1763796&view=rev
Log:
PDFBOX-2852: Changed to not alter value of argument and make creation of PDFunction clearer
by using a switch statement, as suggested by scotty1024 in github PR 6

Modified:
    pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java

Modified: pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java?rev=1763796&r1=1763795&r2=1763796&view=diff
==============================================================================
--- pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java
(original)
+++ pdfbox/trunk/pdfbox/src/main/java/org/apache/pdfbox/pdmodel/common/function/PDFunction.java
Fri Oct  7 16:23:08 2016
@@ -118,34 +118,29 @@ public abstract class PDFunction impleme
             return new PDFunctionTypeIdentity(null);
         }
 
-        PDFunction retval = null;
-        if( function instanceof COSObject )
+        COSDictionary functionDictionary;
+        if (function instanceof COSObject)
         {
-            function = ((COSObject)function).getObject();
+            functionDictionary = (COSDictionary) ((COSObject) function).getObject();
         }
-        COSDictionary functionDictionary = (COSDictionary)function;
-        int functionType = functionDictionary.getInt( COSName.FUNCTION_TYPE );
-        if( functionType == 0 )
-        {
-            retval = new PDFunctionType0(functionDictionary);
-        }
-        else if( functionType == 2 )
-        {
-            retval = new PDFunctionType2(functionDictionary);
-        }
-        else if( functionType == 3 )
-        {
-            retval = new PDFunctionType3(functionDictionary);
-        }
-        else if( functionType == 4 )
+        else
         {
-            retval = new PDFunctionType4(functionDictionary);
+            functionDictionary = (COSDictionary) function;
         }
-        else
+        int functionType = functionDictionary.getInt(COSName.FUNCTION_TYPE);
+        switch (functionType)
         {
-            throw new IOException( "Error: Unknown function type " + functionType );
+            case 0:
+                return new PDFunctionType0(functionDictionary);
+            case 2:
+                return new PDFunctionType2(functionDictionary);
+            case 3:
+                return new PDFunctionType3(functionDictionary);
+            case 4:
+                return new PDFunctionType4(functionDictionary);
+            default:
+                throw new IOException("Error: Unknown function type " + functionType);
         }
-        return retval;
     }
 
     /**



Mime
View raw message