BrightSide Workbench Full Report + Source Code
EntrySet.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.financials.model.register;
19 
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.TreeSet;
23 import org.turro.financials.entity.RegisterEntry;
24 
29 public class EntrySet extends TreeSet<EntryWrapper> {
30 
31  public void addEntry(RegisterEntry entry) {
32  RegisterEntry re = findEqual(entry);
33  if(re != null) {
34  re.setCredit(re.getCredit() + entry.getCredit());
35  re.setDebit(re.getDebit() + entry.getDebit());
36  } else {
37  add(new EntryWrapper(entry));
38  }
39  }
40 
41  public Collection<RegisterEntry> getRegisterEntries() {
42  ArrayList<RegisterEntry> list = new ArrayList<RegisterEntry>();
43  for(EntryWrapper ew : this) {
44  if(!ew.getEntry().isEmpty()) {
45  list.add(ew.getEntry());
46  }
47  }
48  return list;
49  }
50 
51  public void calculateBalance() {
52  double balance = 0;
53  int count = 0;
54  for(EntryWrapper ew : this) {
55  balance += ew.getSingleBalance();
56  ew.getEntry().setEntryOrder(count++);
57  ew.setBalance(balance);
58  }
59  }
60 
61  public void roundEntries(int fractionDigits) {
62  for(EntryWrapper ew : this) {
63  ew.getEntry().roundIt(fractionDigits);
64  }
65  }
66 
67  private RegisterEntry findEqual(RegisterEntry entry) {
68  for(EntryWrapper ew : this) {
69  if(ew.entryEquals(entry)) {
70  return ew.getEntry();
71  }
72  }
73  return null;
74  }
75 
76 }
void addEntry(RegisterEntry entry)
Definition: EntrySet.java:31
void roundEntries(int fractionDigits)
Definition: EntrySet.java:61
Collection< RegisterEntry > getRegisterEntries()
Definition: EntrySet.java:41