Package org.pentaho.reporting.libraries.formula.typing

Examples of org.pentaho.reporting.libraries.formula.typing.TypeRegistry


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

      if (indexType == null || indexValue == null)
      {
        throw new EvaluationException(LibFormulaErrorValue.ERROR_MISSING_ARGUMENT_VALUE);
      }
    }

    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)
    {
      final Number n = typeRegistry.convertToNumber(indexType, indexValue);
      if (n.intValue() >= 1)
      {
        indexFrom = n.intValue() - 1;
      }
      else
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)
        {
          if (logger.isDebugEnabled())
          {
            logger.debug("Failed to evaluate parameter " + pos + " on function " + function);
View Full Code Here

    if (parameters.getParameterCount() != 1)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
    }

    final TypeRegistry typeRegistry = context.getTypeRegistry();
    final Number n = typeRegistry.convertToNumber(parameters.getType(0), parameters.getValue(0));

    if (n == null)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }
View Full Code Here

    final int parameterCount = parameters.getParameterCount();
    if (parameterCount < 3 || parameterCount > 4)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
    }
    final TypeRegistry typeRegistry = context.getTypeRegistry();

    final Type textType = parameters.getType(0);
    final Object textValue = parameters.getValue(0);
    final Type oldTextType = parameters.getType(1);
    final Object oldTextValue = parameters.getValue(1);

    final String text = typeRegistry.convertToText(textType, textValue);
    final String oldText = typeRegistry.convertToText(oldTextType, oldTextValue);
    if (oldText.length() == 0)
    {
      return new TypeValuePair(TextType.TYPE, text);
    }

    final Type newTextType = parameters.getType(2);
    final Object newTextValue = parameters.getValue(2);
    final String newText = typeRegistry.convertToText(newTextType, newTextValue);
    if (parameterCount == 3)
    {
      int index = text.indexOf(oldText);
      if (index == -1)
      {
        return new TypeValuePair(TextType.TYPE, text);
      }

      final StringBuffer result = new StringBuffer(text);
      while (index >= 0)
      {
        result.replace(index, index + oldText.length(), newText);
        index = result.toString().indexOf(oldText, index + newText.length());
      }
      return new TypeValuePair(TextType.TYPE, result.toString());
    }

    // Instead of replacing all occurences, the user only requested to replace
    // a specific one.
    final Type whichType = parameters.getType(3);
    final Object whichValue = parameters.getValue(3);
    final Number n = typeRegistry.convertToNumber(whichType, whichValue);
    if (n.doubleValue() < 1)
    {
      throw new EvaluationException(
          LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }
View Full Code Here

    if (parameters.getParameterCount() != 1)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
    }

    final TypeRegistry typeRegistry = context.getTypeRegistry();
    final Type type = parameters.getType(0);
    final Object value = parameters.getValue(0);

    final Date date1 = typeRegistry.convertToDate(type, value);
    final Date time = DateUtil.normalizeDate(date1, DateTimeType.TIME_TYPE);
    return new TypeValuePair(DateTimeType.TIME_TYPE, time);
  }
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 countType = parameters.getType(1);
    final Object countValue = parameters.getValue(1);

    final int count = typeRegistry.convertToNumber(countType, countValue).intValue();
    if (count < 0)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }

    final Type textType1 = parameters.getType(0);
    final Object textValue1 = parameters.getValue(0);
    final String rawText = typeRegistry.convertToText(textType1, textValue1);
    if(rawText == null)
    {
      return new TypeValuePair(TextType.TYPE, "");
    }
View Full Code Here

    if(parameterCount == 0)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
    }

    final TypeRegistry typeRegistry = context.getTypeRegistry();
    BigDecimal last = null;
    for (int paramIdx = 0; paramIdx < parameterCount; paramIdx++)
    {
      final Type type = parameters.getType(paramIdx);
      final Object value = parameters.getValue(paramIdx);
      final Sequence sequence = typeRegistry.convertToNumberSequence(type, value, isStrictSequenceNeeded());

      while (sequence.hasNext())
      {
        final LValue rawValue = sequence.nextRawValue();
        if (rawValue == null)
        {
          throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
        }
        final TypeValuePair nextValue = rawValue.evaluate();
        final Number number = typeRegistry.convertToNumber(nextValue.getType(), nextValue.getValue());
        final BigDecimal next = NumberUtil.getAsBigDecimal(number);

        if(last == null)
        {
          last = next;
View Full Code Here

    }

    final Type type1 = parameters.getType(0);
    final Object value = parameters.getValue(0);

    final TypeRegistry typeRegistry = context.getTypeRegistry();
    final Number number = typeRegistry.convertToNumber(type1, value);

    if (number == null)
    {
      throw new EvaluationException(
          LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
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 type1 = parameters.getType(0);
    final Object value1 = parameters.getValue(0);
    final Number number1 = typeRegistry.convertToNumber(type1, value1);
    if (number1 == null)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }
    final BigDecimal divided = NumberUtil.getAsBigDecimal(number1);
   
    final Type type2 = parameters.getType(1);
    final Object value2 = parameters.getValue(1);
    final Number number2 = typeRegistry.convertToNumber(type2, value2);
    if (number2 == null)
    {
      throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }
   
View Full Code Here

TOP

Related Classes of org.pentaho.reporting.libraries.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.