EMMA Coverage Report (generated Sat Jan 08 08:46:59 EST 2011)
[all classes][net.sourceforge.finmodel.account]

COVERAGE SUMMARY FOR SOURCE FILE [AccountImpl.java]

nameclass, %method, %block, %line, %
AccountImpl.java100% (1/1)95%  (18/19)94%  (246/263)91%  (52/57)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AccountImpl100% (1/1)95%  (18/19)94%  (246/263)91%  (52/57)
getAverageDailyBalance (Period): BigDecimal 0%   (0/1)0%   (0/5)0%   (0/1)
getTransfers (Calendar): SortedMap 100% (1/1)89%  (94/106)73%  (11/15)
<static initializer> 100% (1/1)100% (4/4)100% (2/2)
AccountImpl (): void 100% (1/1)100% (22/22)100% (7/7)
AccountImpl (String, AssetImpl): void 100% (1/1)100% (28/28)100% (9/9)
addDestinationRule (Rule): void 100% (1/1)100% (6/6)100% (2/2)
addSourceRule (Rule): void 100% (1/1)100% (6/6)100% (2/2)
getAsset (): AssetImpl 100% (1/1)100% (3/3)100% (1/1)
getBalance (Calendar): BigDecimal 100% (1/1)100% (15/15)100% (4/4)
getDestinationRules (): Set 100% (1/1)100% (3/3)100% (1/1)
getId (): long 100% (1/1)100% (3/3)100% (1/1)
getName (): String 100% (1/1)100% (3/3)100% (1/1)
getShares (Calendar): BigDecimal 100% (1/1)100% (32/32)100% (5/5)
getSourceRules (): Set 100% (1/1)100% (3/3)100% (1/1)
removeDestinationRule (Rule): void 100% (1/1)100% (6/6)100% (2/2)
removeSourceRule (Rule): void 100% (1/1)100% (6/6)100% (2/2)
setAsset (AssetImpl): void 100% (1/1)100% (4/4)100% (2/2)
setId (long): void 100% (1/1)100% (4/4)100% (2/2)
setName (String): void 100% (1/1)100% (4/4)100% (2/2)

1package net.sourceforge.finmodel.account;
2 
3import java.io.Serializable;
4import java.math.BigDecimal;
5import java.util.Calendar;
6import java.util.HashSet;
7import java.util.Set;
8import java.util.SortedMap;
9import java.util.TreeMap;
10import java.util.logging.Level;
11import java.util.logging.Logger;
12 
13import net.sourceforge.finmodel.asset.AssetImpl;
14import net.sourceforge.finmodel.rules.Rule;
15 
16import org.jfin.date.Period;
17import org.jfin.date.ScheduleException;
18 
19public class AccountImpl implements Account, Serializable {
20        private static Logger log = Logger.getLogger("net.sourceforge.finmodel.account.AccountImpl");
21        // private static DateFormat dateFormat = new SimpleDateFormat( "MM/dd/yyyy" );
22        
23        private String name = "";
24        private AssetImpl asset = null;
25        private Set<Rule> sourceRules = new HashSet<Rule>();
26        private Set<Rule> destRules = new HashSet<Rule>();
27        
28        // transient private MathContext dollarCtx = new MathContext(2, RoundingMode.HALF_DOWN);
29        private long id = 0L;
30        static final long serialVersionUID = 1L;
31        
32        public AccountImpl() {
33        }
34        
35        public AccountImpl( String name, AssetImpl asset ) {
36                this.name = name;
37                this.asset = asset;
38        }
39        
40        public long getId() {
41                return id;
42        }
43        
44        public void setId( long id ) {
45                this.id = id;
46        }
47        
48        /**
49         * @TODO:  Implement this properly.
50         */
51        public BigDecimal getAverageDailyBalance(Period period) {
52                return getBalance(period.getEndCalendar());
53        }
54 
55        public BigDecimal getBalance(Calendar calendar) {
56                BigDecimal shares = getShares(calendar);
57                BigDecimal cost = getAsset().getEstimatedValue( calendar );
58                BigDecimal rc = shares.multiply(cost);
59                
60                return rc;
61        }
62        
63        private SortedMap<Calendar, BigDecimal> getTransfers(Calendar when)
64        {
65                SortedMap<Calendar, BigDecimal> transfers = new TreeMap<Calendar, BigDecimal>();
66                for (Rule source: getSourceRules()) {
67                        try {
68                                for (Calendar cal: source.getSchedule()) {
69                                        System.err.println("Comparing " + cal + " to " + when);
70                                        if (cal.before(when)) {
71                                                transfers.put( cal, source.createTransaction(cal).getAmount().negate());
72                                        }
73                                }
74                        } catch (ScheduleException sched) {
75                                log.log(Level.WARNING, "ScheduleException for rule: ", sched);
76                        }
77                }
78                
79                for (Rule dest: getDestinationRules()) {
80                        try {
81                                for (Calendar cal: dest.getSchedule()) {
82                                        if (cal.before(when)) {
83                                                transfers.put( cal, dest.createTransaction(cal).getAmount());
84                                        }
85                                }
86                        } catch (ScheduleException sched) {
87                                log.log(Level.WARNING, "ScheduleException for rule: ", sched);
88                        }
89                }
90                
91                return transfers;
92        }
93        
94        /**
95         * @TODO getShares should start at zero, and apply transactions until the
96         * calendar date.  Although, now that I think about it, we may have trouble
97         * with some of the percentage rules as their values change depending on what
98         * the account says it has.  
99         */
100        public BigDecimal getShares( Calendar calendar ) {
101                SortedMap<Calendar, BigDecimal> transfers = getTransfers( calendar );
102                BigDecimal shares = BigDecimal.ZERO;
103                
104                for (Calendar date: transfers.keySet()) {
105                        shares = shares.add(transfers.get(date).divide(getAsset().getEstimatedValue(date)));
106                }
107                
108                return shares;
109        }
110 
111        public void setName(String name) {
112                this.name = name;
113        }
114        
115        public String getName() {
116                return name;
117        }
118        
119        public void setAsset(AssetImpl asset) {
120                this.asset = asset;
121        }
122        
123        public AssetImpl getAsset() {
124                return this.asset;
125        }
126        
127        public Set<Rule> getSourceRules() {
128                return sourceRules;
129        }
130        
131        public void addSourceRule( Rule rule ) {
132                sourceRules.add( rule );
133        }
134        
135        public void removeSourceRule( Rule rule ) {
136                sourceRules.remove(rule);
137        }
138        
139        public Set<Rule> getDestinationRules() {
140                return destRules;
141        }
142        
143        public void addDestinationRule( Rule rule ) {
144                destRules.add( rule );
145        }
146        
147        public void removeDestinationRule( Rule rule ) {
148                destRules.remove( rule );
149        }
150}

[all classes][net.sourceforge.finmodel.account]
EMMA 2.1.5320 (stable) (C) Vladimir Roubtsov