package cse308.swift.server.quotepoller; import java.util.ArrayList; import org.apache.log4j.Logger; import cse308.swift.shared.beans.Quote; /** * This class gets the immediate quote form the yahoo engine * WARNING: if lots of people make losts of purchases, we will likely get limited. * * @author Ken * */ public class ImmediateQuotePoll { static Logger logger = Logger.getLogger(ImmediateQuotePoll.class.getName()); private YahooStockEngine engine; /** * Default */ public ImmediateQuotePoll() { logger.info("Engine Initalized for Immediate Quotes "); engine = new YahooStockEngine(); } /** * Return the Quote for the provided symbol * @param symbol The symbol to ge the quote for : String * @return The Quote for the supplied symbol : Quote */ public Quote getImmediateQuote(String symbol) { Quote retVal = null; ArrayList quotes = engine.fetchQuotes(symbol); if (quotes != null && !quotes.isEmpty()) retVal = quotes.get(0); return retVal; } /** * Returns an array list of quotes, quotes must be valid of exceptions will be thrown * * @param symbols The ArrayList of symbols : ArrayList * @return the ArrayList of Quotes : ArrayList */ public ArrayList getImmediateQuotes(ArrayList symbols) { ArrayList retVal = new ArrayList(); ArrayList quotes = engine.fetchQuotes(symbols); if (quotes != null && !quotes.isEmpty()) for (Quote q : quotes) retVal.add(q); return retVal; } }