BrightSide Workbench Full Report + Source Code
ReportRow.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2020 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.report;
20 
21 import java.util.Objects;
22 import org.turro.string.Strings;
23 import org.turro.financials.entity.RegisterEntry;
24 import org.turro.util.CompareUtil;
25 
30 public class ReportRow implements Comparable<ReportRow> {
31 
32  private final int order;
33  private final String name, group, regexp[];
34  private final ReportSumType sumType;
35  private final boolean sum, negate;
36 
37  public ReportRow(int order, String name, boolean sum, String group) {
38  this.order = order;
39  this.name = name;
40  this.regexp = null;
41  this.sum = sum;
42  this.group = group;
43  this.sumType = null;
44  this.negate = false;
45  }
46 
47  public ReportRow(int order, String name, String regexp[], ReportSumType sumType, boolean negate) {
48  this.order = order;
49  this.name = name;
50  this.regexp = regexp;
51  this.sum = false;
52  this.group = null;
53  this.sumType = sumType;
54  this.negate = negate;
55  }
56 
57  public int getOrder() {
58  return order;
59  }
60 
61  public String getName() {
62  return name;
63  }
64 
65  public String[] getRegexp() {
66  return regexp;
67  }
68 
70  return sumType;
71  }
72 
73  public boolean isNegate() {
74  return negate;
75  }
76 
77  public boolean isSum() {
78  return sum;
79  }
80 
81  public String getGroup() {
82  return Strings.isBlank(group) ? "default" : group;
83  }
84 
85  public boolean check(RegisterEntry e) {
86  if(isSum()) return true;
87  for(String rg : regexp) {
88  if(e.getAccount().getId().matches(rg)) {
89  return true;
90  }
91  }
92  return false;
93  }
94 
95  @Override
96  public int compareTo(ReportRow o) {
97  int result = CompareUtil.compare(order, o.getOrder());
98  if(result == 0) {
99  result = CompareUtil.compare(name, o.getName());
100  }
101  return result;
102  }
103 
104  @Override
105  public int hashCode() {
106  return Objects.hash(order, name, regexp, sumType);
107  }
108 
109 }
ReportRow(int order, String name, boolean sum, String group)
Definition: ReportRow.java:37
ReportRow(int order, String name, String regexp[], ReportSumType sumType, boolean negate)
Definition: ReportRow.java:47
boolean check(RegisterEntry e)
Definition: ReportRow.java:85