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

COVERAGE SUMMARY FOR SOURCE FILE [FinancialPlan.java]

nameclass, %method, %block, %line, %
FinancialPlan.java0%   (0/1)0%   (0/16)0%   (0/189)0%   (0/53)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class FinancialPlan0%   (0/1)0%   (0/16)0%   (0/189)0%   (0/53)
FinancialPlan (): void 0%   (0/1)0%   (0/17)0%   (0/5)
addAccount (Account, BigDecimal): void 0%   (0/1)0%   (0/22)0%   (0/7)
addRule (RuleImpl): void 0%   (0/1)0%   (0/9)0%   (0/3)
allPlans (): List 0%   (0/1)0%   (0/9)0%   (0/3)
getAccounts (): Set 0%   (0/1)0%   (0/28)0%   (0/5)
getId (): long 0%   (0/1)0%   (0/3)0%   (0/1)
getName (): String 0%   (0/1)0%   (0/3)0%   (0/1)
getRules (): Set 0%   (0/1)0%   (0/3)0%   (0/1)
getScheduledTransactions (): List 0%   (0/1)0%   (0/41)0%   (0/7)
getSession (): Session 0%   (0/1)0%   (0/13)0%   (0/4)
load (long): FinancialPlan 0%   (0/1)0%   (0/9)0%   (0/2)
removeRule (RuleImpl): void 0%   (0/1)0%   (0/6)0%   (0/2)
save (): void 0%   (0/1)0%   (0/14)0%   (0/6)
setId (long): void 0%   (0/1)0%   (0/4)0%   (0/2)
setName (String): void 0%   (0/1)0%   (0/4)0%   (0/2)
setRules (Set): void 0%   (0/1)0%   (0/4)0%   (0/2)

1package net.sourceforge.finmodel.plan;
2 
3import java.math.BigDecimal;
4import java.util.ArrayList;
5import java.util.Calendar;
6import java.util.Collections;
7import java.util.HashSet;
8import java.util.List;
9import java.util.Set;
10 
11import net.sourceforge.finmodel.account.Account;
12import net.sourceforge.finmodel.account.AccountImpl;
13import net.sourceforge.finmodel.account.CashAccount;
14import net.sourceforge.finmodel.rules.OneTimeRule;
15import net.sourceforge.finmodel.rules.Rule;
16import net.sourceforge.finmodel.rules.RuleImpl;
17 
18import org.hibernate.Session;
19import org.hibernate.SessionFactory;
20import org.hibernate.Transaction;
21import org.hibernate.cfg.Configuration;
22import org.jfin.date.ScheduleException;
23 
24public class FinancialPlan {
25        private long id;
26        private String name;
27        private Set<RuleImpl> rules = new HashSet<RuleImpl>();
28        private AccountImpl openingBalance;
29        private Calendar initiationDate;
30        
31//        private List<Account> accounts = new ArrayList<Account>();
32        
33        public FinancialPlan() {
34                this.name = "New Plan";
35                this.openingBalance = new CashAccount("Opening Balance");
36        }
37        
38        private static Session getSession() {
39                Session session = null;
40                
41                SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
42                session = sessionFactory.openSession();
43                
44                return session;
45        }
46        
47        public void save() {
48                Session session = getSession();
49                Transaction tx = session.beginTransaction();                
50                session.save(this);
51                session.flush();
52                tx.commit();
53        }
54        
55        public static FinancialPlan load( long id )
56        {
57                Session session = getSession();                
58                return (FinancialPlan) session.load(FinancialPlan.class, id);                
59        }
60        
61        public static List<FinancialPlan> allPlans() 
62        {
63                Session session = getSession();
64                List<FinancialPlan> rc = session.createQuery("from net.sourceforge.finmodel.plan.FinancialPlan").list();
65                
66                return rc;
67        }
68        
69        public void addAccount( Account acct, BigDecimal openingBal) {
70                OneTimeRule openRule = new OneTimeRule();
71                openRule.setSource( openingBalance );
72                openRule.setDestination(acct);
73                openRule.setAmount(openingBal);
74                openRule.setDate(initiationDate);
75                
76                addRule(openRule);
77        }
78        
79        public Set<Account> getAccounts() {
80                Set<Account> rc = new HashSet<Account>();
81                
82                for (RuleImpl rule: rules) {
83                        rc.add(rule.getSource());
84                        rc.add(rule.getDestination());
85                }
86                
87                return rc;
88        }
89        
90        public void setRules( Set<RuleImpl> rules ) {
91                this.rules = rules;
92        }
93        
94        public Set<RuleImpl> getRules() {
95                return this.rules;
96        }
97        
98        public void addRule( RuleImpl rule ) {
99                rules.add( rule );
100                rule.setPlan(this);
101        }
102        
103        public void removeRule( RuleImpl rule ) {
104                rules.remove( rule );
105        }
106        
107        public List<net.sourceforge.finmodel.plan.Transaction> getScheduledTransactions() 
108                throws ScheduleException
109        {
110                List<net.sourceforge.finmodel.plan.Transaction> rc =
111                        new ArrayList<net.sourceforge.finmodel.plan.Transaction>();
112                for (Rule rule: rules) {
113                        for (Calendar time: rule.getSchedule()) {
114                                rc.add( rule.createTransaction( time ));
115                        }
116                }
117                Collections.sort(rc, new TransactionComparator());
118                return rc;
119        }
120 
121        /**
122         * @param name the name to set
123         */
124        public void setName(String name) {
125                this.name = name;
126        }
127 
128        /**
129         * @return the name
130         */
131        public String getName() {
132                return name;
133        }
134 
135        /**
136         * @param id the id to set
137         */
138        public void setId(long id) {
139                this.id = id;
140        }
141 
142        /**
143         * @return the id
144         */
145        public long getId() {
146                return id;
147        }
148}

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