public final class OperandResolver extends Object
Modifier and Type | Method and Description |
---|---|
static ValueEval |
chooseMultipleElementsFromArea(AreaEval ae,
int srcCellRow,
int srcCellCol) |
static ValueEval |
chooseSingleElementFromArea(AreaEval ae,
int srcCellRow,
int srcCellCol)
Implements (some perhaps not well known) Excel functionality to select a single cell from an
area depending on the coordinates of the calling cell.
|
static Boolean |
coerceValueToBoolean(ValueEval ve,
boolean stringsAreBlanks) |
static double |
coerceValueToDouble(ValueEval ev)
Applies some conversion rules if the supplied value is not already a number.
|
static int |
coerceValueToInt(ValueEval ev)
Applies some conversion rules if the supplied value is not already an integer.
Value is first coerced to a double ( See coerceValueToDouble() ). |
static long |
coerceValueToLong(ValueEval ev)
Applies some conversion rules if the supplied value is not already a long integer.
Value is first coerced to a double ( See coerceValueToDouble() ). |
static String |
coerceValueToString(ValueEval ve) |
static ValueEval |
getMultipleValue(ValueEval arg,
int srcCellRow,
int srcCellCol) |
static ValueEval |
getSingleValue(ValueEval arg,
int srcCellRow,
int srcCellCol)
Retrieves a single value from a variety of different argument types according to standard
Excel rules.
|
static Double |
parseDouble(String pText)
Converts a string to a double using standard rules that Excel would use.
Tolerates leading and trailing spaces, Doesn't support currency prefixes, commas, percentage signs or arithmetic operations strings. |
public static ValueEval getSingleValue(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException
arg
- the evaluated argument as passed to the function or operator.srcCellRow
- used when arg is a single column AreaRefsrcCellCol
- used when arg is a single row AreaRefnull
or ErrorEval.EvaluationException(#VALUE!)
- if srcCellRow or srcCellCol do not properly index into
an AreaEval. If the actual value retrieved is an ErrorEval, a corresponding
EvaluationException is thrown.EvaluationException
public static ValueEval chooseSingleElementFromArea(AreaEval ae, int srcCellRow, int srcCellCol) throws EvaluationException
A | B | C | D | |
---|---|---|---|---|
1 | 15 | 20 | 25 | |
2 | 200 | |||
3 | 300 | |||
3 | 400 |
A | B | C | D | |
---|---|---|---|---|
1 | 15 | 20 | 25 | |
2 | 1215 | 1220 | #VALUE! | 200 |
3 | 1315 | 1320 | #VALUE! | 300 |
4 | #VALUE! | #VALUE! | #VALUE! | 400 |
null
. Never
ErrorEval.EvaluationException
- if there is a problem with indexing into the area, or if the
evaluated cell has an error.public static int coerceValueToInt(ValueEval ev) throws EvaluationException
0
.
Excel typically converts doubles to integers by truncating toward negative infinity.return (int)Math.floor(d);
return (int)d; // wrong - rounds toward zero
EvaluationException
public static double coerceValueToDouble(ValueEval ev) throws EvaluationException
NumberEval.ZERO
.ev
- must be a NumberEval
, StringEval
, BoolEval
or
BlankEval
EvaluationException(#VALUE!)
- only if a StringEval is supplied and cannot be parsed
as a double (See parseDouble() for allowable formats).RuntimeException
- if the supplied parameter is not NumberEval
,
StringEval
, BoolEval
or BlankEval
EvaluationException
public static Double parseDouble(String pText)
null
if the specified text cannot be parsed as a numberpublic static String coerceValueToString(ValueEval ve)
ve
- must be a NumberEval, StringEval, BoolEval, or BlankEvalnull
public static Boolean coerceValueToBoolean(ValueEval ve, boolean stringsAreBlanks) throws EvaluationException
null
to represent blank valuesEvaluationException
- if ve is an ErrorEval, or if a string value cannot be convertedpublic static long coerceValueToLong(ValueEval ev) throws EvaluationException
0
.
Excel typically converts doubles to integers by truncating toward negative infinity.return (long)Math.floor(d);
return (long)d; // wrong - rounds toward zero
EvaluationException
public static ValueEval chooseMultipleElementsFromArea(AreaEval ae, int srcCellRow, int srcCellCol) throws EvaluationException
EvaluationException
public static ValueEval getMultipleValue(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException
EvaluationException
Copyright © 2020. All rights reserved.