BrightSide Workbench Full Report + Source Code
EntryWrapper.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 org.turro.financials.entity.RegisterEntry;
21 import org.turro.util.CompareUtil;
22 
27 public class EntryWrapper implements Comparable<EntryWrapper> {
28 
29  private RegisterEntry entry;
30  private double balance;
31 
32  public EntryWrapper(RegisterEntry entry) {
33  this.entry = entry;
34  }
35 
36  public double getBalance() {
37  return balance;
38  }
39 
40  public void setBalance(double balance) {
41  this.balance = balance;
42  }
43 
45  return entry;
46  }
47 
48  public void setEntry(RegisterEntry entry) {
49  this.entry = entry;
50  }
51 
52  public double getSingleBalance() {
53  return entry.getDebit() - entry.getCredit();
54  }
55 
56  public boolean entryEquals(RegisterEntry re) {
57  return entry.getAccount().getId().equals(re.getAccount().getId()) &&
58  entry.getConcept().equals(re.getConcept()) &&
59  ((entry.getCredit() != 0 && re.getCredit() != 0) ||
60  (entry.getDebit() != 0 && re.getDebit() != 0));
61 
62  }
63 
64  @Override
65  public int compareTo(EntryWrapper o) {
66  int result = 0;
67  if(entry.getAccount() != null && o.getEntry().getAccount() != null) {
68  result = entry.getAccount().getId().compareTo(o.getEntry().getAccount().getId());
69  }
70  if(result == 0) {
71  result = CompareUtil.compare(entry.getConcept(), o.getEntry().getConcept());
72  }
73  if(result == 0) {
74  result = CompareUtil.compare(entry.getDebit(), o.getEntry().getDebit());
75  }
76  if(result == 0) {
77  result = CompareUtil.compare(entry.getCredit(), o.getEntry().getCredit());
78  }
79  if(result == 0) {
80  result = CompareUtil.compare(entry.getId(), o.getEntry().getId());
81  }
82  return result;
83  }
84 
85  @Override
86  public boolean equals(Object obj) {
87  if (obj == null) {
88  return false;
89  }
90  if (getClass() != obj.getClass()) {
91  return false;
92  }
93  final EntryWrapper other = (EntryWrapper) obj;
94  if(this.entry != other.entry && (this.entry == null || !(this.entry.getId() == other.entry.getId()))) {
95  return false;
96  }
97  return true;
98  }
99 
100  @Override
101  public int hashCode() {
102  int hash = 3;
103  hash = 37 * hash + (this.entry != null ? this.entry.hashCode() : 0);
104  return hash;
105  }
106 
107 }