BrightSide Workbench Full Report + Source Code
PeriodSet.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.report;
19 
20 import java.util.Date;
21 import java.util.TreeSet;
22 import org.amic.util.date.CheckDate;
23 
28 public class PeriodSet extends TreeSet<AccountReportPeriod> {
29 
30  private int year = 0, month = 0;
31 
32  public PeriodSet() {
33  super(new PeriodComparator());
34  }
35 
37  for(AccountReportPeriod p : this) {
38  if(p.equals(period)) {
39  return p;
40  }
41  }
42  return null;
43  }
44 
45  public void fillGapsTillNow(AccountReportItem item) {
46  AccountReportPeriod arp = first();
47  if(arp != null) {
48  CheckDate cd = new CheckDate(arp.getYear(), arp.getMonth(), 1, 0, 0, 0);
49  Date now = new Date();
50  while(cd.compareMonthYear(now) == -1) {
51  AccountReportPeriod a = new AccountReportPeriod(cd.getYear(), cd.getMonth());
52  a.setValue(0);
53  a.setItem(item);
54  add(a);
55  cd.addMonths(1);
56  }
57  }
58  }
59 
60  public PeriodSet getCurrentPeriod(int count) {
61  if(year == 0 || month == 0) {
62  CheckDate cd = new CheckDate();
63  cd.addMonths(-(count/2));
64  year = cd.getYear();
65  month = cd.getMonth();
66  }
67  PeriodSet ps = new PeriodSet();
68  int c = 0;
69  for(AccountReportPeriod arp : tailSet(new AccountReportPeriod(year, month))) {
70  ps.add(arp);
71  if(c++ > count - 1) break;
72  }
73  return ps;
74  }
75 
76  public void incrementPeriod(int amount) {
77  CheckDate cd = new CheckDate(year, month, 1, 0, 0, 0);
78  cd.addMonths(amount);
79  year = cd.getYear();
80  month = cd.getMonth();
81  }
82 }
PeriodSet getCurrentPeriod(int count)
Definition: PeriodSet.java:60
void fillGapsTillNow(AccountReportItem item)
Definition: PeriodSet.java:45
AccountReportPeriod getPeriod(AccountReportPeriod period)
Definition: PeriodSet.java:36