use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestTrunc method testTruncWithStringArg.
public void testTruncWithStringArg() {
ValueEval strArg = new StringEval("abc");
ValueEval[] args = { strArg, new NumberEval(2) };
ValueEval result = NumericFunction.TRUNC.evaluate(args, -1, (short) -1);
assertEquals(ErrorEval.VALUE_INVALID, result);
}
use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestRoundFuncs method testRoundDownWithStringArg.
@Test
public void testRoundDownWithStringArg() {
ValueEval strArg = new StringEval("abc");
ValueEval[] args = { strArg, new NumberEval(2) };
ValueEval result = NumericFunction.ROUNDDOWN.evaluate(args, -1, (short) -1);
assertEquals(ErrorEval.VALUE_INVALID, result);
}
use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestRoundFuncs method testRoundUpWithStringArg.
@Test
public void testRoundUpWithStringArg() {
ValueEval strArg = new StringEval("abc");
ValueEval[] args = { strArg, new NumberEval(2) };
ValueEval result = NumericFunction.ROUNDUP.evaluate(args, -1, (short) -1);
assertEquals(ErrorEval.VALUE_INVALID, result);
}
use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class TestMatch method testSimpleWildcardValuesString.
public void testSimpleWildcardValuesString() {
// Arrange
ValueEval[] values = { new StringEval("Albert"), new StringEval("Charles"), new StringEval("Ed"), new StringEval("Greg"), new StringEval("Ian") };
AreaEval ae = EvalFactory.createAreaEval("A1:A5", values);
// Note String comparisons are case insensitive
confirmInt(3, invokeMatch(new StringEval("e*"), ae, MATCH_EXACT));
confirmInt(3, invokeMatch(new StringEval("*d"), ae, MATCH_EXACT));
confirmInt(1, invokeMatch(new StringEval("Al*"), ae, MATCH_EXACT));
confirmInt(2, invokeMatch(new StringEval("Char*"), ae, MATCH_EXACT));
confirmInt(4, invokeMatch(new StringEval("*eg"), ae, MATCH_EXACT));
confirmInt(4, invokeMatch(new StringEval("G?eg"), ae, MATCH_EXACT));
confirmInt(4, invokeMatch(new StringEval("??eg"), ae, MATCH_EXACT));
confirmInt(4, invokeMatch(new StringEval("G*?eg"), ae, MATCH_EXACT));
confirmInt(4, invokeMatch(new StringEval("Hugh"), ae, MATCH_LARGEST_LTE));
confirmInt(5, invokeMatch(new StringEval("*Ian*"), ae, MATCH_EXACT));
confirmInt(5, invokeMatch(new StringEval("*Ian*"), ae, MATCH_LARGEST_LTE));
}
use of org.apache.poi.ss.formula.eval.StringEval in project poi by apache.
the class Dec2Bin method evaluate.
public ValueEval evaluate(int srcRowIndex, int srcColumnIndex, ValueEval numberVE, ValueEval placesVE) {
ValueEval veText1;
try {
veText1 = OperandResolver.getSingleValue(numberVE, srcRowIndex, srcColumnIndex);
} catch (EvaluationException e) {
return e.getErrorEval();
}
String strText1 = OperandResolver.coerceValueToString(veText1);
Double number = OperandResolver.parseDouble(strText1);
//If this number argument is non numeric, this function returns the #VALUE! error value.
if (number == null) {
return ErrorEval.VALUE_INVALID;
}
//If number < -512 or if number > 512, this function returns the #NUM! error value.
if (number.longValue() < MIN_VALUE || number.longValue() > MAX_VALUE) {
return ErrorEval.NUM_ERROR;
}
int placesNumber;
if (number < 0 || placesVE == null) {
placesNumber = DEFAULT_PLACES_VALUE;
} else {
ValueEval placesValueEval;
try {
placesValueEval = OperandResolver.getSingleValue(placesVE, srcRowIndex, srcColumnIndex);
} catch (EvaluationException e) {
return e.getErrorEval();
}
String placesStr = OperandResolver.coerceValueToString(placesValueEval);
Double placesNumberDouble = OperandResolver.parseDouble(placesStr);
//non numeric value
if (placesNumberDouble == null) {
return ErrorEval.VALUE_INVALID;
}
//If this argument contains a decimal value, this function ignores the numbers to the right side of the decimal point.
placesNumber = placesNumberDouble.intValue();
if (placesNumber < 0 || placesNumber == 0) {
return ErrorEval.NUM_ERROR;
}
}
String binary = Integer.toBinaryString(number.intValue());
if (binary.length() > DEFAULT_PLACES_VALUE) {
binary = binary.substring(binary.length() - DEFAULT_PLACES_VALUE, binary.length());
}
//If DEC2BIN requires more than places characters, it returns the #NUM! error value.
if (binary.length() > placesNumber) {
return ErrorEval.NUM_ERROR;
}
return new StringEval(binary);
}
Aggregations