poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cedricwal...@apache.org
Subject svn commit: r1531395 - in /poi/trunk: src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java src/java/org/apache/poi/ss/formula/functions/Dec2Hex.java test-data/spreadsheet/FormulaEvalTestData.xls
Date Fri, 11 Oct 2013 19:16:44 GMT
Author: cedricwalter
Date: Fri Oct 11 19:16:43 2013
New Revision: 1531395

URL: http://svn.apache.org/r1531395
Log:
Bug 55036: patch for missing function Dec2HEx

Modified:
    poi/trunk/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java
    poi/trunk/src/java/org/apache/poi/ss/formula/functions/Dec2Hex.java
    poi/trunk/test-data/spreadsheet/FormulaEvalTestData.xls

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java?rev=1531395&r1=1531394&r2=1531395&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/atp/AnalysisToolPak.java Fri Oct 11 19:16:43
2013
@@ -89,7 +89,7 @@ public final class AnalysisToolPak imple
         r(m, "CUMIPMT", null);
         r(m, "CUMPRINC", null);
         r(m, "DEC2BIN", Dec2Bin.instance);
-        r(m, "DEC2HEX", null);
+        r(m, "DEC2HEX", Dec2Hex.instance);
         r(m, "DEC2OCT", null);
         r(m, "DELTA", Delta.instance);
         r(m, "DISC", null);

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/functions/Dec2Hex.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/functions/Dec2Hex.java?rev=1531395&r1=1531394&r2=1531395&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/functions/Dec2Hex.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/functions/Dec2Hex.java Fri Oct 11 19:16:43
2013
@@ -45,7 +45,7 @@ import org.apache.poi.ss.formula.eval.*;
  * <ul>
  * <li>If this argument is omitted, this function uses the minimum number of characters
necessary.</li>
  * <li>If this function requires more than places characters, it returns the #NUM!
error value.</li>
- * <li>If this argument is nonnumeric, this function returns the #VALUE! error value.</li>
+ * <li>If this argument is non numeric, this function returns the #VALUE! error value.</li>
  * <li>If this argument is negative, this function returns the #NUM! error value.</li>
  * <li>If this argument contains a decimal value, this function ignores the numbers
to the right side of the decimal point.</li>
  * </ul>
@@ -54,9 +54,11 @@ import org.apache.poi.ss.formula.eval.*;
  */
 public final class Dec2Hex extends Var1or2ArgFunction implements FreeRefFunction {
 
-    private final static long MIN_VALUE = new Long("-549755813888").longValue();
-    private final static long MAX_VALUE = new Long("549755813887").longValue();
-    private final static int DEFAULT_PLACES_VALUE = 10;;
+    public static final FreeRefFunction instance = new Dec2Hex();
+
+    private final static long MIN_VALUE = Long.parseLong("-549755813888");
+    private final static long MAX_VALUE = Long.parseLong("549755813887");
+    private final static int DEFAULT_PLACES_VALUE = 10;
 
     public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval number, ValueEval
places) {
         ValueEval veText1;
@@ -81,7 +83,8 @@ public final class Dec2Hex extends Var1o
         int placesNumber = 0;
         if (number1 < 0) {
             placesNumber = DEFAULT_PLACES_VALUE;
-        } else  {
+        }
+        else if (places != null) {
             ValueEval placesValueEval;
             try {
                 placesValueEval = OperandResolver.getSingleValue(places, srcRowIndex, srcColumnIndex);
@@ -104,26 +107,32 @@ public final class Dec2Hex extends Var1o
             }
         }
 
-        String hex = "";
+        String hex;
         if (placesNumber != 0) {
-            hex = String.format("%0"+placesNumber+"X", number1.intValue() & 0x0FFFFF);
+            hex = String.format("%0"+placesNumber+"X", number1.intValue());
         }
         else {
             hex = Integer.toHexString(number1.intValue());
         }
 
+        if (number1 < 0) {
+            hex =  "FF"+  hex.substring(2);
+        }
+
         return new StringEval(hex.toUpperCase());
     }
 
     public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval arg0) {
-        return this.evaluate(srcRowIndex, srcColumnIndex, arg0, new StringEval(String.valueOf(DEFAULT_PLACES_VALUE)));
+        return this.evaluate(srcRowIndex, srcColumnIndex, arg0, null);
     }
 
     public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
-        if (args.length != 2) {
-            return ErrorEval.VALUE_INVALID;
+        if (args.length == 1) {
+            return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0]);
         }
-        return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]);
+        if (args.length == 2) {
+            return evaluate(ec.getRowIndex(), ec.getColumnIndex(), args[0], args[1]);
+        }
+        return ErrorEval.VALUE_INVALID;
     }
-
-}
\ No newline at end of file
+}

Modified: poi/trunk/test-data/spreadsheet/FormulaEvalTestData.xls
URL: http://svn.apache.org/viewvc/poi/trunk/test-data/spreadsheet/FormulaEvalTestData.xls?rev=1531395&r1=1531394&r2=1531395&view=diff
==============================================================================
Binary files - no diff available.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message