BrightSide Workbench Full Report + Source Code
AmountSet.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;
19 
20 import java.util.Iterator;
21 import java.util.TreeSet;
22 
27 public class AmountSet extends TreeSet<Amount> {
28 
29  @Override
30  public boolean add(Amount e) {
31  e.setAmountSet(this);
32  return super.add(e);
33  }
34 
35  public void addAmount(Amount e) {
36  Amount a = getAmount(e.getTax());
37  if(a == null) {
38  add(e);
39  } else {
40  a.addTax(e.getTax(), e.getSubtotal(), e.getDiscount(), e.getRetained());
41  }
42  }
43 
44  public double getTaxable() {
45  double amount = 0;
46  for(Amount a : this) {
47  amount += a.getTaxable();
48  }
49  return amount;
50  }
51 
52  public double getTaxValue() {
53  double amount = 0;
54  for(Amount a : this) {
55  amount += a.getTaxValue();
56  }
57  return amount;
58  }
59 
60  public Amount getAmount(Double tax) {
61  for(Amount a : this) {
62  if(a.getTax().equals(tax)) {
63  return a;
64  }
65  }
66  return null;
67  }
68 
69  public double getAmount() {
70  double amount = 0;
71  for(Amount a : this) {
72  amount += a.getAmount();
73  }
74  return amount;
75  }
76 
77  public void clearEmpty() {
78  Iterator<Amount> it = iterator();
79  while(it.hasNext()) {
80  if(it.next().isEmpty()) {
81  it.remove();
82  }
83  }
84  }
85 
86 }
void setAmountSet(AmountSet amountSet)
Definition: Amount.java:40
void addTax(Double tax, Double subtotal, Double discount, Double retained)
Definition: Amount.java:48