// 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); } }
/** * Return the window title. * * @return the window title */ public String getTitle() { // Title depends on the quote bundle we are listing String title = Locale.getString("TABLE_OF", quoteBundle.getQuoteRange().getDescription()); // If there is only one date it makes sense to tell the user it if (singleDate) title = title.concat(" (" + quoteBundle.getLastDate().toString("dd/mm/yyyy") + ")"); return title; }
// This function extracts all quotes from the quote bundle and returns // them as a list of Quotes. private List extractAllQuotes(EODQuoteBundle quoteBundle) { List quotes = new ArrayList(); Iterator iterator = quoteBundle.iterator(); TradingDate lastDate = quoteBundle.getLastDate(); // Traverse all symbols on all dates while (iterator.hasNext()) { Quote quote = (Quote) iterator.next(); if (!singleDate || (lastDate.equals(quote.getDate()))) quotes.add(quote); } return quotes; }