} else {
retval = new FuncPtg(funcIx);
}
- if (!name.equals(AbstractFunctionPtg.FUNCTION_NAME_IF)) {
+ if (!name.equalsIgnoreCase(AbstractFunctionPtg.FUNCTION_NAME_IF)) {
// early return for everything else besides IF()
return retval;
}
}
}
- final OperationPtg o = (OperationPtg) ptg;
- int nOperands = o.getNumberOfOperands();
- final String[] operands = new String[nOperands];
-
- for (int j = nOperands-1; j >= 0; j--) { // reverse iteration because args were pushed in-order
- if(stack.isEmpty()) {
- String msg = "Too few arguments suppled to operation token ("
- + o.getClass().getName() + "). Expected (" + nOperands
- + ") operands but got (" + (nOperands - j - 1) + ")";
- throw new IllegalStateException(msg);
- }
- operands[j] = (String) stack.pop();
- }
+ OperationPtg o = (OperationPtg) ptg;
+ String[] operands = getOperands(stack, o.getNumberOfOperands());
stack.push(o.toFormulaString(operands));
}
if(stack.isEmpty()) {
}
return result;
}
+
+ private static String[] getOperands(Stack stack, int nOperands) {
+ String[] operands = new String[nOperands];
+
+ for (int j = nOperands-1; j >= 0; j--) { // reverse iteration because args were pushed in-order
+ if(stack.isEmpty()) {
+ String msg = "Too few arguments supplied to operation. Expected (" + nOperands
+ + ") operands but got (" + (nOperands - j - 1) + ")";
+ throw new IllegalStateException(msg);
+ }
+ operands[j] = (String) stack.pop();
+ }
+ return operands;
+ }
/**
* Static method to convert an array of Ptgs in RPN order
* to a human readable string format in infix mode. Works
Class[] expClss;
- expClss = new Class[] { ReferencePtg.class, MissingArgPtg.class, ReferencePtg.class,
- FuncVarPtg.class, };
+ expClss = new Class[] {
+ ReferencePtg.class,
+ AttrPtg.class, // tAttrIf
+ MissingArgPtg.class,
+ AttrPtg.class, // tAttrSkip
+ ReferencePtg.class,
+ AttrPtg.class, // tAttrSkip
+ FuncVarPtg.class,
+ };
+
confirmTokenClasses("if(A1, ,C1)", expClss);
expClss = new Class[] { MissingArgPtg.class, AreaPtg.class, MissingArgPtg.class,
fail("Expected exception was not thrown");
} catch (IllegalStateException e) {
// expected during successful test
- assertTrue(e.getMessage().startsWith("Too few arguments suppled to operation token"));
+ assertTrue(e.getMessage().startsWith("Too few arguments supplied to operation"));
}
}
/**