Package org.jfree.formula.lvalues

Examples of org.jfree.formula.lvalues.TypeValuePair


  public TypeValuePair evaluate(final FormulaContext context,
                                final ParameterCallback parameters)
      throws EvaluationException
  {
    final SumFunction sumFunction = new SumFunction();
    final TypeValuePair sum = sumFunction.evaluate(context, parameters);

    final Number n = context.getTypeRegistry().convertToNumber(sum.getType(), sum.getValue());
    final BigDecimal divident = NumberUtil.getAsBigDecimal(n);
    final BigDecimal divisor = new BigDecimal(parameters.getParameterCount());
    final BigDecimal avg = divident.divide(divisor, 40, BigDecimal.ROUND_HALF_UP);

    return new TypeValuePair(NumberType.GENERIC_NUMBER, avg);
  }
View Full Code Here


  {
    final int parameterCount = parameters.getParameterCount();

    if(parameterCount == 0)
    {
      return new TypeValuePair(NumberType.GENERIC_NUMBER, ZERO);
    }

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

      while(sequence.hasNext())
      {
        final BigDecimal next = NumberUtil.getAsBigDecimal(sequence.nextNumber());
        if(last == null)
        {
          last = next;
        }
        else
        {
          if(last.compareTo(next) == 1)
          {
            last = next;
          }
        }
      }
    }
    if(last == null)
    {
      throw new EvaluationException(
          LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
    }

    return new TypeValuePair(NumberType.GENERIC_NUMBER, last);
  }
View Full Code Here

      {
        reminder = divided.add(divisor);
      }
    }

    return new TypeValuePair(NumberType.GENERIC_NUMBER, reminder);
  }
View Full Code Here

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

    final Object indexValue = parameters.getValue(0);

    final int index= context.getTypeRegistry().convertToNumber(indexType, indexValue).intValue();
    if(index >= 1 && index < parameters.getParameterCount())
    {
      return new TypeValuePair(parameters.getType(index), parameters.getValue(index));
    }
    // else
    throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
  }
View Full Code Here

  {
    final LocalizationContext localizationContext = context.getLocalizationContext();
    final Date now = DateUtil.now(localizationContext);

    final Date date = DateUtil.normalizeDate(now, DateTimeType.DATETIME_TYPE);
    return new TypeValuePair(DateTimeType.DATETIME_TYPE, date);
  }
View Full Code Here

  {
  }

  public TypeValuePair evaluate(final FormulaContext context, final ParameterCallback parameters) throws EvaluationException
  {
    final TypeValuePair typeValuePair = super.evaluate(context, parameters);
    if(typeValuePair.getValue().equals(Boolean.TRUE))
    {
      return RETURN_FALSE;
    }
    else
    {
View Full Code Here

    final Calendar gc = DateUtil.createCalendar(d, context
        .getLocalizationContext());

    final int year = gc
            .get(Calendar.YEAR);
    return new TypeValuePair(NumberType.GENERIC_NUMBER, new Integer(year));
  }
View Full Code Here

    final Calendar gc = DateUtil.createCalendar(d, context
        .getLocalizationContext());

    final int dayOfWeek = gc.get(Calendar.DAY_OF_WEEK);
    // in java Sunday = 1 (= Type 1 of openformula)
    return new TypeValuePair(NumberType.GENERIC_NUMBER, new Integer(
        convertType(dayOfWeek, type)));
  }
View Full Code Here

            .performIntRounding(bd).intValue());
    final BigDecimal dayFraction = bd.subtract(round1);
    final Integer hour = NumberUtil.performIntRounding(dayFraction
        .multiply(HOUR_24));

    return new TypeValuePair(NumberType.GENERIC_NUMBER, hour);
  }
View Full Code Here

TOP

Related Classes of org.jfree.formula.lvalues.TypeValuePair

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.