Package org.jfree.formula

Examples of org.jfree.formula.EvaluationException


  public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException
  {
    final int parameterCount = parameters.getParameterCount();
    if (parameterCount < 1)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
    }
    final Type type1 = parameters.getType(0);
    final Object value1 = parameters.getValue(0);
    final String result = context.getTypeRegistry().convertToText(type1, value1);

    if(result == null)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }

    return new TypeValuePair(TextType.TYPE, result);
  }
View Full Code Here


                                ParameterCallback parameters)
      throws EvaluationException
  {
    if(parameters.getParameterCount() < 1)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
    }
    final int length = parameters.getParameterCount();
    for (int i = 0; i < length; i++)
    {
      final Type conditionType = parameters.getType(i);
      final Object conditionValue = parameters.getValue(i);
      final Boolean condition = context.getTypeRegistry().convertToLogical(conditionType, conditionValue);
      if(condition == null)
      {
        throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
      }
      if (Boolean.TRUE.equals(condition))
      {
        return RETURN_TRUE;
      }
View Full Code Here

  public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException
  {
    final int parameterCount = parameters.getParameterCount();
    if (parameterCount != 2)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
    }
    final TypeRegistry typeRegistry = context.getTypeRegistry();

    final Type textType1 = parameters.getType(0);
    final Object textValue1 = parameters.getValue(0);
    final Type textType2 = parameters.getType(1);
    final Object textValue2 = parameters.getValue(1);


    // Numerical comparisons ignore "trivial" differences that
    // depend only on numeric precision of finite numbers.

    // This fixes the common rounding errors, that are encountered when computing "((1/3) * 3)", which results
    // in 0.99999 and not 1, as expected.
    try
    {
      final Number number1 = typeRegistry.convertToNumber(textType1, textValue1);
      final Number number2 = typeRegistry.convertToNumber(textType2, textValue2);

      final double delta = Math.abs(Math.abs(number1.doubleValue()) - Math.abs(number2.doubleValue()));
      if(delta < 0.00005)
      {
        return RETURN_TRUE;
      }
      return RETURN_FALSE;
    }
    catch(TypeConversionException tce)
    {
      // Ignore, try to compare them as strings ..
    }

    final String text1 = typeRegistry.convertToText(textType1, textValue1);
    final String text2 = typeRegistry.convertToText(textType2, textValue2);
    if(text1 == null || text2 == null)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }

    if (text1.equals(text2))
    {
      return RETURN_TRUE;
View Full Code Here

      throws EvaluationException
  {
    final int parameterCount = parameters.getParameterCount();
    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);
View Full Code Here

  public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException
  {
    final int parameterCount = parameters.getParameterCount();
    if (parameterCount < 2 || parameterCount > 3)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
    }
    final TypeRegistry typeRegistry = context.getTypeRegistry();

    final Type searchType = parameters.getType(0);
    final Object searchValue = parameters.getValue(0);
    final Type textType = parameters.getType(1);
    final Object textValue = parameters.getValue(1);
    Type indexType = null;
    Object indexValue = null;

    if (parameterCount == 3)
    {
      indexType = parameters.getType(2);
      indexValue = parameters.getValue(2);
    }

    final String search = typeRegistry.convertToText(searchType, searchValue);
    final String text = typeRegistry.convertToText(textType, textValue);

    if (search == null || text == null)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }
    int indexFrom = 0;

    if (indexType != null && indexValue != null)
    {
      final Number n = typeRegistry.convertToNumber(indexType, indexValue);
      if (n.intValue() >= 1)
      {
        indexFrom = n.intValue() - 1;
      }
      else
      {
        throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
      }
    }

    final int index = text.indexOf(search, indexFrom);
    if (index < 0)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_NOT_FOUND_VALUE);
    }

    return new TypeValuePair(NumberType.GENERIC_NUMBER, new BigDecimal(index + 1));
  }
View Full Code Here

                                ParameterCallback parameters)
      throws EvaluationException
  {
    if(parameters.getParameterCount() != 0)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
    }
    return RETURN_FALSE;
  }
View Full Code Here

  public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException
  {
    final int parameterCount = parameters.getParameterCount();
    if (parameterCount < 1)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
    }
    final Type type1 = parameters.getType(0);
    final Object value1 = parameters.getValue(0);
    final String result = context.getTypeRegistry().convertToText(type1, value1);

    if(result == null)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }

    return new TypeValuePair(TextType.TYPE, result.toLowerCase(context.getLocalizationContext().getLocale()));
  }
View Full Code Here

  public static BigDecimal getAsBigDecimal(final Number number) throws EvaluationException
  {
    if (number == null)
    {
      throw new EvaluationException(
          LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }
   
    if(number instanceof BigDecimal)
    {
View Full Code Here

    // Error or empty string, that's the question ..
    final Object raw1 = value1.getValue();
    final Object raw2 = value2.getValue();
    if (raw1 == null || raw2 == null)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_NA_VALUE);
    }

    final String text1 = typeRegistry.convertToText(value1.getType(), raw1);
    final String text2 = typeRegistry.convertToText(value2.getType(), raw2);
    if (text1 == null && text2 == null)
    {
      throw new EvaluationException
          (LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }
    if (text1 == null)
    {
      return new TypeValuePair(TextType.TYPE, text2);
View Full Code Here

  {
    final Type type = value1.getType();
    final Object val = value1.getValue();
    if (val == null)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_NA_VALUE);
    }
   
    if (type.isFlagSet(Type.NUMERIC_TYPE))
    {
      final TypeRegistry typeRegistry = context.getTypeRegistry();
      // return the same as zero minus value.
      final Number number = typeRegistry.convertToNumber(type, val);
      final BigDecimal value = getAsBigDecimal(number);
      return new TypeValuePair(type, ZERO.subtract(value));
    }

    if(val instanceof Number)
    {
      final BigDecimal value = getAsBigDecimal((Number)val);
      return new TypeValuePair(type, ZERO.subtract(value));
    }

    throw new EvaluationException
        (LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
  }
View Full Code Here

TOP

Related Classes of org.jfree.formula.EvaluationException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.