if (parameterCount < 2)
{
throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
}
final Type conditionType = parameters.getType(0);
final Object conditionValue = parameters.getValue(0);
final Boolean condition = context.getTypeRegistry().convertToLogical(conditionType, conditionValue);
if(condition == null)
{
throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
}
if (Boolean.TRUE.equals(condition))
{
final Object value = parameters.getValue(1);
final Type type = parameters.getType(1);
return new TypeValuePair(type, value);
}
// if condition is false and no third parameter, return false
if(parameterCount == 2 || parameters.getValue(2) == null)
{
return RETURN_FALSE;
}
// else return third parameter
final Object value = parameters.getValue(2);
final Type type = parameters.getType(2);
return new TypeValuePair(type, value);
}