BrightSide Workbench Full Report + Source Code
AmountRetained.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2013 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 
19 package org.turro.financials.model.document;
20 
21 import org.turro.math.Round;
22 
27 public class AmountRetained implements Comparable<AmountRetained> {
28 
29  private Double perCent, taxable;
30  private int fractionDigits;
31 
32  public AmountRetained(Double perCent) {
33  this.perCent = perCent;
34  taxable = 0.0;
35  }
36 
37  public void add(Double taxable) {
38  this.taxable += taxable;
39  }
40 
41  public boolean isPerCent(Double perCent) {
42  return this.perCent.equals(perCent);
43  }
44 
45  public void setFractionDigits(int fractionDigits) {
46  this.fractionDigits = fractionDigits;
47  }
48 
49  public Double getRetention() {
50  return perCent;
51  }
52 
53  public Double getTaxable() {
54  return taxable;
55  }
56 
57  public Double getRetained() {
58  return new Round((taxable * (perCent / 100.0))).decimals(fractionDigits).value();
59  }
60 
61  public boolean isEmpty() {
62  return taxable == null || taxable == 0 || taxable.isNaN();
63  }
64 
65  @Override
66  public int hashCode() {
67  int hash = 7;
68  hash = 37 * hash + (this.perCent != null ? this.perCent.hashCode() : 0);
69  return hash;
70  }
71 
72  @Override
73  public boolean equals(Object obj) {
74  if (obj == null) {
75  return false;
76  }
77  if (getClass() != obj.getClass()) {
78  return false;
79  }
80  final AmountRetained other = (AmountRetained) obj;
81  if (this.perCent != other.perCent && (this.perCent == null || !this.perCent.equals(other.perCent))) {
82  return false;
83  }
84  return true;
85  }
86 
87  @Override
88  public int compareTo(AmountRetained o) {
89  return perCent.compareTo(o.perCent);
90  }
91 
92 }
Round decimals(int digits)
Definition: Round.java:32