Java Reference
In-Depth Information
Collection <? extends
extends StockOptionPrice > getOptions ();
}
The sample applications typically deal with a collection of these prices, representing the his-
tory of the stock over a period of time (e.g., 1 year or 25 years, depending on the example):
public
public interface
interface StockPriceHistory
StockPriceHistory {
StockPrice getPrice ( Date d );
Collection < StockPrice > getPrices ( Date startDate , Date endDate );
Map < Date , StockPrice > getAllEntries ();
Map < BigDecimal , ArrayList < Date >> getHistogram ();
BigDecimal getAveragePrice ();
Date getFirstDate ();
BigDecimal getHighPrice ();
Date getLastDate ();
BigDecimal getLowPrice ();
BigDecimal getStdDev ();
String getSymbol ();
}
The basic implementation of this class loads a set of prices from the database:
public
public class
class StockPriceHistoryImpl
StockPriceHistoryImpl implements
implements StockPriceHistory {
...
public
public StockPriceHistoryImpl ( String s , Date startDate ,
Date endDate , EntityManager em ) {
Date curDate = new
new Date ( startDate . getTime ());
symbol = s ;
while
while (! curDate . after ( endDate )) {
StockPriceImpl sp = em . find ( StockPriceImpl . class ,
new
new StockPricePK ( s , ( Date ) curDate . clone ()));
iif ( sp != null
null ) {
Date d = ( Date ) curDate . clone ();
iif ( firstDate == null
null ) {
firstDate = d ;
}
prices . put ( d , sp );
lastDate = d ;
}
curDate . setTime ( curDate . getTime () + msPerDay );
}
}
Search WWH ::




Custom Search