BrightSide Workbench Full Report + Source Code
AccountItem.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.db.FinancialsPU;
21 import org.turro.financials.entity.Account;
22 import org.turro.financials.entity.RegisterView;
23 import org.turro.jpa.Dao;
24 import org.turro.math.Zero;
25 import org.turro.util.CompareUtil;
26 
31 public class AccountItem implements Comparable<AccountItem> {
32 
34  public Account account;
35  public double balance;
36 
38  if(!Zero.near(balance, 2)) {
39  return new AccountItem(view, account, balance);
40  }
41  return null;
42  }
43 
45  this.view = view;
46  this.account = account;
47  this.balance = balance;
48  }
49 
50  public AccountItem(long idView, String idAccount, double balance) {
51  Dao dao = new FinancialsPU();
52  this.view = dao.find(RegisterView.class, idView);
53  this.account = dao.find(Account.class, idAccount);
54  this.balance = balance;
55  }
56 
57  @Override
58  public boolean equals(Object obj) {
59  if (obj == null) {
60  return false;
61  }
62  if (getClass() != obj.getClass()) {
63  return false;
64  }
65  final AccountItem other = (AccountItem) obj;
66  if (this.view != other.view && (this.view == null || !this.view.equals(other.view))) {
67  return false;
68  }
69  if (this.account != other.account && (this.account == null || !this.account.equals(other.account))) {
70  return false;
71  }
72  if (Double.doubleToLongBits(this.balance) != Double.doubleToLongBits(other.balance)) {
73  return false;
74  }
75  return true;
76  }
77 
78  @Override
79  public int hashCode() {
80  int hash = 7;
81  hash = 19 * hash + (this.view != null ? this.view.hashCode() : 0);
82  hash = 19 * hash + (this.account != null ? this.account.hashCode() : 0);
83  hash = 19 * hash + (int) (Double.doubleToLongBits(this.balance) ^ (Double.doubleToLongBits(this.balance) >>> 32));
84  return hash;
85  }
86 
87  @Override
88  public int compareTo(AccountItem o) {
89  int result = CompareUtil.compare(view.getId(), o.view.getId());
90  if(result == 0) {
91  result = CompareUtil.compare(account.getId(), o.account.getId());
92  }
93  if(result == 0) {
94  result = CompareUtil.compare(balance, o.balance);
95  }
96  return result;
97  }
98 
99 }
AccountItem(long idView, String idAccount, double balance)
static AccountItem createAccountItem(RegisterView view, Account account, double balance)
AccountItem(RegisterView view, Account account, double balance)
static boolean near(double value, int digits)
Definition: Zero.java:30