BrightSide Workbench Full Report + Source Code
ValuesSet.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.operating;
20 
21 import java.util.TreeSet;
22 
27 public class ValuesSet extends TreeSet<ValueItem> {
28 
29  public ValueItem getItem(String major) {
30  ValueItem vi = ceiling(new ValueItem(major));
31  if(vi != null && vi.getMajor().equals(major)) {
32  return vi;
33  } else {
34  vi = new ValueItem(major);
35  add(vi);
36  return vi;
37  }
38  }
39 
40  public TreeSet<ValueItem> getSales() {
41  TreeSet<ValueItem> sub = new TreeSet<>();
42  for(ValueItem vi : this) {
43  if(vi.getMajor().startsWith("7")) {
44  sub.add(vi);
45  }
46  }
47  return sub;
48  }
49 
50  public TreeSet<ValueItem> getExpenses() {
51  TreeSet<ValueItem> sub = new TreeSet<>();
52  for(ValueItem vi : this) {
53  if(vi.getMajor().startsWith("6")) {
54  sub.add(vi);
55  }
56  }
57  return sub;
58  }
59 
60  public double getSalesAmount() {
61  double amount = 0;
62  for(ValueItem vi : getSales()) {
63  amount += vi.getValue();
64  }
65  return amount;
66  }
67 
68  public double getExpensesAmount() {
69  double amount = 0;
70  for(ValueItem vi : getExpenses()) {
71  amount += vi.getValue();
72  }
73  return amount;
74  }
75 
76 }
TreeSet< ValueItem > getExpenses()
Definition: ValuesSet.java:50