Exemplo n.º 1
0
 /**
  * Test method for {@link EvaluationException#EvaluationException(java.lang.String,
  * java.lang.Throwable)}.
  */
 @Test
 public void testEvaluationExceptionStringThrowable() {
   Throwable cause = new Throwable();
   EvaluationException exception = new EvaluationException("my message", cause);
   assertEquals("my message", exception.getMessage());
   assertEquals(cause, exception.getCause());
 }
Exemplo n.º 2
0
 /** Test method for {@link EvaluationException#EvaluationException(java.lang.Throwable)}. */
 @Test
 public void testEvaluationExceptionThrowable() {
   Throwable cause = new Throwable();
   EvaluationException exception = new EvaluationException(cause);
   assertEquals(cause.toString(), exception.getMessage());
   assertEquals(cause, exception.getCause());
 }
Exemplo n.º 3
0
  // Extract all quotes from the quote bundle which cause the given
  // expression to equate to true. If there is no expression (string is null or
  // empty) then extract all the quotes.
  private List extractQuotesUsingRule(String filterExpression, EODQuoteBundle quoteBundle) {

    // If there is no rule, then just return all quotes
    if (filterExpression == null || filterExpression.length() == 0)
      return extractAllQuotes(quoteBundle);

    // First parse the expression
    Expression expression = null;

    try {
      expression = Parser.parse(filterExpressionString);
    } catch (ExpressionException e) {
      // We should have already checked the string for errors before here
      assert false;
    }

    // Add symbols to list when expression proves true
    ArrayList quotes = new ArrayList();
    Iterator iterator = quoteBundle.iterator();
    TradingDate lastDate = quoteBundle.getLastDate();

    try {
      // Traverse all symbols on all dates
      while (iterator.hasNext()) {
        Quote quote = (Quote) iterator.next();
        Symbol symbol = quote.getSymbol();
        TradingDate date = quote.getDate();
        int dateOffset = 0;

        try {
          dateOffset = quoteBundle.dateToOffset(date);
        } catch (WeekendDateException e) {
          assert false;
        }

        if (!singleDate || (lastDate.equals(quote.getDate()))) {
          if (expression.evaluate(new Variables(), quoteBundle, symbol, dateOffset)
              >= Expression.TRUE_LEVEL) quotes.add(quote);
        }
      }

      return quotes;
    } catch (EvaluationException e) {
      // Tell user expression didnt evaluate properly
      JOptionPane.showInternalMessageDialog(
          DesktopManager.getDesktop(),
          e.getReason() + ": " + expression.toString(),
          Locale.getString("ERROR_EVALUATION_EQUATION"),
          JOptionPane.ERROR_MESSAGE);

      // delete erroneous expression
      expression = null;

      // If the expression didn't evaluate then just return all the quotes
      return extractAllQuotes(quoteBundle);
    }
  }
Exemplo n.º 4
0
  public ValueEval evaluate(
      final ValueEval[] args, final int srcRowIndex, final int srcColumnIndex) {
    if (args.length == 0 || args.length > 2) {
      // Wrong number of arguments
      return ErrorEval.VALUE_INVALID;
    }

    try {
      double[] values = AggregateFunction.ValueCollector.collectValues(args[0]);
      double guess;
      if (args.length == 2) {
        guess = NumericFunction.singleOperandEvaluate(args[1], srcRowIndex, srcColumnIndex);
      } else {
        guess = 0.1d;
      }
      double result = irr(values, guess);
      NumericFunction.checkValue(result);
      return new NumberEval(result);
    } catch (EvaluationException e) {
      return e.getErrorEval();
    }
  }
Exemplo n.º 5
0
 /** Test method for {@link EvaluationException#EvaluationException(java.lang.String)}. */
 @Test
 public void testEvaluationExceptionString() {
   EvaluationException exception = new EvaluationException("my message");
   assertEquals("my message", exception.getMessage());
   assertNull(exception.getCause());
 }
Exemplo n.º 6
0
 /** Test method for {@link EvaluationException#EvaluationException()}. */
 @Test
 public void testEvaluationException() {
   EvaluationException exception = new EvaluationException();
   assertNull(exception.getMessage());
   assertNull(exception.getCause());
 }