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

COVERAGE SUMMARY FOR SOURCE FILE [RuleImpl.java]

nameclass, %method, %block, %line, %
RuleImpl.java100% (1/1)60%  (12/20)85%  (155/183)78%  (40/51)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class RuleImpl100% (1/1)60%  (12/20)85%  (155/183)78%  (40/51)
getAmount (Calendar): BigDecimal 0%   (0/1)0%   (0/3)0%   (0/1)
getDest (): Account 0%   (0/1)0%   (0/3)0%   (0/1)
getId (): long 0%   (0/1)0%   (0/3)0%   (0/1)
getPlan (): FinancialPlan 0%   (0/1)0%   (0/3)0%   (0/1)
getSchedule (): List 0%   (0/1)0%   (0/4)0%   (0/1)
setDest (Account): void 0%   (0/1)0%   (0/4)0%   (0/2)
setId (long): void 0%   (0/1)0%   (0/4)0%   (0/2)
setPlan (FinancialPlan): void 0%   (0/1)0%   (0/4)0%   (0/2)
RuleImpl (): void 100% (1/1)100% (11/11)100% (4/4)
addRuleListener (RuleListener): void 100% (1/1)100% (6/6)100% (2/2)
createTransaction (Calendar): Transaction 100% (1/1)100% (18/18)100% (4/4)
getDestination (): Account 100% (1/1)100% (3/3)100% (1/1)
getSource (): Account 100% (1/1)100% (3/3)100% (1/1)
makeTransaction (Calendar, BigDecimal): Transaction 100% (1/1)100% (10/10)100% (1/1)
notifyDestinationChange (Account): void 100% (1/1)100% (17/17)100% (3/3)
notifyScheduleChange (): void 100% (1/1)100% (16/16)100% (3/3)
notifySourceChange (Account): void 100% (1/1)100% (17/17)100% (3/3)
removeRuleListener (RuleListener): void 100% (1/1)100% (6/6)100% (2/2)
setDestination (Account): void 100% (1/1)100% (24/24)100% (8/8)
setSource (Account): void 100% (1/1)100% (24/24)100% (8/8)

1package net.sourceforge.finmodel.rules;
2 
3import java.io.Serializable;
4import java.math.BigDecimal;
5import java.util.ArrayList;
6import java.util.Calendar;
7import java.util.HashSet;
8import java.util.List;
9import java.util.Set;
10 
11import org.jfin.date.ScheduleException;
12 
13import net.sourceforge.finmodel.account.Account;
14import net.sourceforge.finmodel.plan.FinancialPlan;
15import net.sourceforge.finmodel.plan.Transaction;
16import net.sourceforge.finmodel.plan.TransactionImpl;
17 
18public class RuleImpl implements Rule, Serializable {
19        public static final long serialVersionUID = 1L;
20        
21        private long id;
22        private Account source;
23        private Account dest;
24        private FinancialPlan plan;
25        private Set<RuleListener> listeners = new HashSet<RuleListener>();
26 
27        protected BigDecimal amount = BigDecimal.ZERO;
28        
29        public RuleImpl() {
30                super();
31        }
32 
33        public void setSource(Account source) {
34                Account oldSource = this.source;
35                this.source = source;
36                source.addSourceRule( this );
37                if (oldSource != null) {
38                        oldSource.removeSourceRule( this );
39                }
40                
41                if (oldSource == null || !oldSource.equals(source)) {
42                        notifySourceChange(oldSource);
43                }
44        }
45 
46        public Account getSource() {
47                return source;
48        }
49 
50        public void setDestination(Account dest) {
51                Account oldDest = this.dest;
52                this.dest = dest;
53                dest.addDestinationRule( this );
54                if (oldDest != null) {
55                        oldDest.removeDestinationRule( this );
56                }
57                
58                if (oldDest == null || !oldDest.equals(dest)) {
59                        notifyDestinationChange(oldDest);
60                }
61        }
62 
63        public Account getDestination() {
64                return dest;
65        }
66 
67        protected void notifyScheduleChange() {
68                for (RuleListener listener: listeners) {
69                        listener.eventScheduleChange(this);
70                }
71        }
72 
73        protected void notifySourceChange(Account oldSource) {
74                for (RuleListener listener: listeners) {
75                        listener.eventSourceChange(this, oldSource);
76                }                
77        }
78 
79        protected void notifyDestinationChange(Account oldDest) {
80                for (RuleListener listener: listeners) {
81                        listener.eventDestinationChange(this, oldDest);
82                }                                
83        }
84 
85        public void addRuleListener(RuleListener listener) {
86                listeners.add(listener);
87        }
88 
89        public void removeRuleListener(RuleListener listener) {
90                listeners.remove(listener);
91        }
92 
93        /**
94         * @param dest the dest to set
95         */
96        protected void setDest(Account dest) {
97                this.dest = dest;
98        }
99 
100        /**
101         * @return the dest
102         */
103        protected Account getDest() {
104                return dest;
105        }
106 
107        /**
108         * @param id the id to set
109         */
110        public void setId(long id) {
111                this.id = id;
112        }
113 
114        /**
115         * @return the id
116         */
117        public long getId() {
118                return id;
119        }
120 
121        public List<Calendar> getSchedule() throws ScheduleException {
122                return new ArrayList<Calendar>();
123        }
124 
125        /**
126         * @param plan the plan to set
127         */
128        public void setPlan(FinancialPlan plan) {
129                this.plan = plan;
130        }
131 
132        /**
133         * @return the plan
134         */
135        public FinancialPlan getPlan() {
136                return plan;
137        }
138 
139        protected Transaction makeTransaction(Calendar date, BigDecimal value) {
140                return new TransactionImpl(getSource(), getDestination(), date, value );
141        }
142        
143        /**
144         * This method is called by createTransaction, only
145         * after it has established that there is a scheduled
146         * payment - so it is safe to do whatever calculations
147         * are required in here, without worrying to see if 
148         * we have a scheduled transaction on this day.
149         * 
150         * @param day
151         * @return
152         */
153        protected BigDecimal getAmount(Calendar day) {
154                return amount;
155        }
156        
157        /**
158         * This will create a transaction for the specific day
159         * passed in.  If the day is not in the schedule, it will
160         * return ZERO in the amount field.
161         * 
162         * @param day - Day to create the Transaction for.
163         * @throws ScheduleException - If we are unable to create our schedule.
164         */
165        public Transaction createTransaction(Calendar day) 
166                throws ScheduleException
167        {
168                List<Calendar> sched = getSchedule();
169                if (sched.contains(day)) {
170                        return makeTransaction(day, amount);
171                } else {
172                        return makeTransaction(day, BigDecimal.ZERO);
173                }
174        }
175}

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