public TypeValuePair evaluateTyped()
{
try
{
final TypeValuePair typeValuePair = rootReference.evaluate();
if (typeValuePair == null)
{
throw EvaluationException.getInstance(LibFormulaErrorValue.ERROR_NA_VALUE);
}
final Type type = typeValuePair.getType();
if (type.isFlagSet(Type.ERROR_TYPE))
{
logger.debug("Error: " + typeValuePair.getValue());
}
else if (type.isFlagSet(Type.ARRAY_TYPE))
{
final Object value = typeValuePair.getValue();
if (value instanceof ArrayCallback)
{
return new TypeValuePair(type, new StaticArrayCallback((ArrayCallback) value));
}
}
else
{
final Object value = typeValuePair.getValue();
if (value instanceof Number)
{
return new TypeValuePair(type, NumberUtil.performTuneRounding(NumberUtil.getAsBigDecimal((Number) value)));
}
}
return typeValuePair;
}
catch (EvaluationException ee)
{
return new TypeValuePair(ErrorType.TYPE, ee.getErrorValue());
}
catch (Exception e)
{
logger.warn("Evaluation failed unexpectedly: ", e);
return new TypeValuePair(ErrorType.TYPE, LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE);
}
}