use of org.apache.poi.ss.formula.eval.RefEval in project poi by apache.
the class TestSumproduct method testScalarSimple.
public void testScalarSimple() {
RefEval refEval = EvalFactory.createRefEval("A1", new NumberEval(3));
ValueEval[] args = { refEval, new NumberEval(2) };
ValueEval result = invokeSumproduct(args);
confirmDouble(6D, result);
}
use of org.apache.poi.ss.formula.eval.RefEval in project poi by apache.
the class TestMid method testUnusualArgs.
/**
* Valid cases where args are not precisely (string, int, int) but can be resolved OK.
*/
public void testUnusualArgs() {
// startPos with fractional digits
confirmMid(new StringEval("galactic"), new NumberEval(3.1), new NumberEval(4), "lact");
// string startPos
confirmMid(new StringEval("galactic"), new StringEval("3"), new NumberEval(4), "lact");
// text (first) arg type is number, other args are strings with fractional digits
confirmMid(new NumberEval(123456), new StringEval("3.1"), new StringEval("2.9"), "34");
// startPos is 1x1 area ref, numChars is cell ref
AreaEval aeStart = EvalFactory.createAreaEval("A1:A1", new ValueEval[] { new NumberEval(2) });
RefEval reNumChars = EvalFactory.createRefEval("B1", new NumberEval(3));
confirmMid(new StringEval("galactic"), aeStart, reNumChars, "ala");
confirmMid(new StringEval("galactic"), new NumberEval(3.1), BlankEval.instance, "");
confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.FALSE, "");
confirmMid(new StringEval("galactic"), new NumberEval(3), BoolEval.TRUE, "l");
confirmMid(BlankEval.instance, new NumberEval(3), BoolEval.TRUE, "");
}
use of org.apache.poi.ss.formula.eval.RefEval in project poi by apache.
the class EvaluationConditionalFormatRule method unwrapEval.
private ValueEval unwrapEval(ValueEval eval) {
ValueEval comp = eval;
while (comp instanceof RefEval) {
RefEval ref = (RefEval) comp;
comp = ref.getInnerValueEval(ref.getFirstSheetIndex());
}
return comp;
}
use of org.apache.poi.ss.formula.eval.RefEval in project poi by apache.
the class EDate method getValue.
private double getValue(ValueEval arg) throws EvaluationException {
if (arg instanceof NumberEval) {
return ((NumberEval) arg).getNumberValue();
}
if (arg instanceof BlankEval) {
return 0;
}
if (arg instanceof RefEval) {
RefEval refEval = (RefEval) arg;
if (refEval.getNumberOfSheets() > 1) {
// Multi-Sheet references are not supported
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
ValueEval innerValueEval = refEval.getInnerValueEval(refEval.getFirstSheetIndex());
if (innerValueEval instanceof NumberEval) {
return ((NumberEval) innerValueEval).getNumberValue();
}
if (innerValueEval instanceof BlankEval) {
return 0;
}
}
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
use of org.apache.poi.ss.formula.eval.RefEval in project poi by apache.
the class Bin2Dec method evaluate.
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE) {
final String number;
if (numberVE instanceof RefEval) {
RefEval re = (RefEval) numberVE;
number = OperandResolver.coerceValueToString(re.getInnerValueEval(re.getFirstSheetIndex()));
} else {
number = OperandResolver.coerceValueToString(numberVE);
}
if (number.length() > 10) {
return ErrorEval.NUM_ERROR;
}
String unsigned;
//If the leftmost bit is 0 -- number is positive.
boolean isPositive;
if (number.length() < 10) {
unsigned = number;
isPositive = true;
} else {
unsigned = number.substring(1);
isPositive = number.startsWith("0");
}
String value;
try {
if (isPositive) {
//bit9*2^8 + bit8*2^7 + bit7*2^6 + bit6*2^5 + bit5*2^4+ bit3*2^2+ bit2*2^1+ bit1*2^0
int sum = getDecimalValue(unsigned);
value = String.valueOf(sum);
} else {
//The leftmost bit is 1 -- this is negative number
//Inverse bits [1-9]
String inverted = toggleBits(unsigned);
// Calculate decimal number
int sum = getDecimalValue(inverted);
//Add 1 to obtained number
sum++;
value = "-" + sum;
}
} catch (NumberFormatException e) {
return ErrorEval.NUM_ERROR;
}
return new NumberEval(Long.parseLong(value));
}
Aggregations