Chapter 5. Model
Data model of the application consists of following classes
- Symbol – holds details about a symbol
- DataGroup – holds various categories of data like BS (Balance Sheet), PL (Profit and Loss), CF (Cash Flow) etc
- Data – segregates the data into different time periods.
- Fact – holds key and value for each item of financial indicator
Figure 5.1. UML diagram of the Model
Figure 5.2. Example Data
- Symbol holds name of company and a list of two DataGroup – one for category BS and another for PL.
- Each DataGroup holds a list of two Data – one for 31 Dec 2011 and another for 31 Dec 2012
- Each Data holds list of two Fact pertaining to a time period.
- Each Fact contains a key and value.
Model classes are in in.fins.client package. Apart from getters and setters they also provide some additional methods for basic operations
Import Fins Code
Figure 5.3. Sample selection
war/WEB-INF/classes. Project may throw strange errors if old classes are lying around in that directory.
in.finspackage (including all sub packages) from src directory to remove everything from src dir. Next, do a fresh import of required chapter/section, clean the project and do a GWT compile.
addDataGroup(DataGroup)– Add dataGroup to List<DataGroup>. Creates ArrayList if list is null.
getDataGroup(String category)– returns DataGroup for a category.
addData(Data)– Add data to List<Data>. Creates ArrayList if list is null.
getData(Date)– returns Data for a date from dataList.
firstDate()– returns lowest date from dataList.
lastDate()– returns highest date from dataList.
getDateList()– returns sorted list of dates from dataList.
addFact(Fact)– Add fact to List<Fact>. Creates ArrayList if list is null.
compareTo(Data)– implementation of Comparable interface. Compares date field of Data with date field of data passed as argument.
SymbolHelperwith following static methods.
getDataGroup(Symbol, String category)returns DataGroup of a category
getData(Symbol, String category, Date)returns Data of a category for a date
getFacts(Symbol, String category, Date)returns List<Fact> for a category and date.
getFact(Symbol, String category, Date, String key)returns Fact for a date, category and key.
getLastDate(Symbol, String category)returns maximum Date for a category.
getPositionDate(Symbol, String category)returns Date for a category for which data is displayed.
getOffsetDate(Symbol, String category, Date, int offset)returns Date for a category which is date + offset. For example if symbol hold data for four dates 31 Mar 2011, 30 Jun 2011, Sep 2011 and 31 Dec 2011 then for date 30 Sep 2011 offset 1 returns 31 Dec 2011, offset -1 returns 30 Sep 2011, offset -2 returns 31 Mar 2011 and offset 0 returns 30 Sep 2011
getCategories(Symbol)returns List<String> with all category names which symbol is holding.
addFact(Symbol, String category, Date, Fact fact)add the Fact to Symbol. Fact is inserted to Data with specific Date of DataGroup of specific category.
setPositionDate(Symbol, String category, Date)set poistionDate to date for particular category.
setFacts(Symbol, String category, Date, List<Fact>)List<Fact> is set to particular Data of a DataGroup.
updateSymbol(Symbol srcSymbol, Symbol dstSymbol)copy data structure from srcSymbol to dstSymbol
replaceData(Symbol, String category, Data)replace Symbol’s Data for a category with given Data.
This part of book deals with client code, and therefore we are not making any call to the server. We need some data to display and in-memory data store in.fins.client.SymbolDatabase constructs and provides random data for symbols. It has private methods to construct data for various categories like BS, PL etc. It provides data to clients through two public methods.
- List<String> getSymbolNames() – returns list of symbol names
- Symbol getSymbol(String name,Map<String, String> filterMap) – for a given name returns a fully populated Symbol.
Table 5.1. Dates
|Quote||Monthly||31 Jan 2012, 29 Feb 2012 . . . . 31 Dec 2012|
|Holding||Monthly||31 Jan 2012, 29 Feb 2012 . . . . 31 Dec 2012|
|Quarterly||Quarterly||30 Sep 2011, 31 Dec 2011 . . . . 30 Sep 2012|
|BS||Yearly||31 Dec 2007, 31 Dec 2008 . . . . 31 Dec 2012|
|PL||Yearly||31 Dec 2007, 31 Dec 2008 . . . . 31 Dec 2012|
|Cash Flow||Yearly||31 Dec 2007, 31 Dec 2008 . . . . 31 Dec 2012|
SymbolDatabaseyou will notice couple of GWT classes,
com.google.gwt.i18n.client.DateTimeFormat. Java also offers
Randomfor generation of random numbers and