Package org.jfree.formula.typing

Examples of org.jfree.formula.typing.TypeRegistry


  public TypeValuePair evaluate(final FormulaContext context,
                                final TypeValuePair value1,
                                final TypeValuePair value2)
      throws EvaluationException
  {
    final TypeRegistry typeRegistry = context.getTypeRegistry();
    final Object value1Raw = value1.getValue();
    final Object value2Raw = value2.getValue();
    if (value1Raw == null || value2Raw == null)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_NA_VALUE);
    }

    final Type type1 = value1.getType();
    final Type type2 = value2.getType();
    final ExtendedComparator comparator = typeRegistry.getComparator(type1, type2);
    final boolean result = comparator.isEqual (type1, value1Raw, type2, value2Raw);
    if (result)
    {
      return RETURN_TRUE;
    }
View Full Code Here


    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);
    }

View Full Code Here

    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
View Full Code Here

  public TypeValuePair evaluate(final FormulaContext context,
                                final TypeValuePair value1,
                                final TypeValuePair value2)
      throws EvaluationException
  {
    final TypeRegistry typeRegistry = context.getTypeRegistry();

    // 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);
    }
View Full Code Here

      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)
View Full Code Here

  public TypeValuePair evaluate(final FormulaContext context,
                                final TypeValuePair value1,
                                final TypeValuePair value2)
      throws EvaluationException
  {
    final TypeRegistry typeRegistry = context.getTypeRegistry();
    final Object value1Raw = value1.getValue();
    final Object value2Raw = value2.getValue();
    if (value1Raw == null || value2Raw == null)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_NA_VALUE);
    }

    final Type type1 = value1.getType();
    final Type type2 = value2.getType();
    final ExtendedComparator comparator = typeRegistry.getComparator(type1, type2);
    final boolean result = comparator.isEqual (type1, value1Raw, type2, value2Raw);
    if (result)
    {
      return RETURN_TRUE;
    }
View Full Code Here

      final Type paramType = function.metaData.getParameterType(pos);
      if (parameter != null)
      {
        final TypeValuePair result = parameter.evaluate();
        // lets do some type checking, right?
        final TypeRegistry typeRegistry = function.getContext().getTypeRegistry();
        final TypeValuePair converted = typeRegistry.convertTo(paramType, result);
        if (converted == null)
        {
          Log.debug("Failed to evaluate parameter " + pos + " on function " + function);
          throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_AUTO_ARGUMENT_VALUE);
        }
View Full Code Here

  public final TypeValuePair evaluate(final FormulaContext context,
                                      final TypeValuePair value1,
                                      final TypeValuePair value2)
      throws EvaluationException
  {
    final TypeRegistry typeRegistry = context.getTypeRegistry();
    final Type type1 = value1.getType();
    final Type type2 = value2.getType();
    final Object value1Raw = value1.getValue();
    final Object value2Raw = value2.getValue();
    if (value1Raw == null || value2Raw == null)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_NA_VALUE);
    }

    final ExtendedComparator comparator = typeRegistry.getComparator(type1, type2);
    final Integer result = comparator.compare (type1, value1Raw, type2, value2Raw);
    if (result == null)
    {
      throw new EvaluationException
          (LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
View Full Code Here

  public TypeValuePair evaluate(final FormulaContext context,
                                final TypeValuePair value1, final TypeValuePair value2)
      throws EvaluationException
  {
    final TypeRegistry typeRegistry = context.getTypeRegistry();

    final ExtendedComparator comparator =
        typeRegistry.getComparator(value1.getType(), value2.getType());
    final boolean result = comparator.isEqual
        (value1.getType(), value1.getValue(),
            value2.getType(), value2.getValue());

    if (result == false)
View Full Code Here

  public final TypeValuePair evaluate(final FormulaContext context,
                                      final TypeValuePair value1,
                                      final TypeValuePair value2)
      throws EvaluationException
  {
    final TypeRegistry typeRegistry = context.getTypeRegistry();

    if (value1 == null || value2 == null)
    {
      // If this happens, then one of the implementations has messed up.
      throw new EvaluationException(LibFormulaErrorValue.ERROR_UNEXPECTED_VALUE);
View Full Code Here

TOP

Related Classes of org.jfree.formula.typing.TypeRegistry

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.