BrightSide Workbench Full Report + Source Code
ReportColumn.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.financials.entity.RegisterEntry;
23 import org.turro.util.CompareUtil;
24 
29 public class ReportColumn implements Comparable<ReportColumn> {
30 
31  private final int order;
32  private final String name;
33  private final String regexp[];
34 
35  public ReportColumn(int order, String name, String regexp[]) {
36  this.order = order;
37  this.name = name;
38  this.regexp = regexp;
39  }
40 
41  public int getOrder() {
42  return order;
43  }
44 
45  public String getName() {
46  return name;
47  }
48 
49  public String[] getRegexp() {
50  return regexp;
51  }
52 
53  public boolean check(RegisterEntry e) {
54  for(String rg : regexp) {
55  if(e.getAccount().getId().matches(rg)) {
56  return true;
57  }
58  }
59  return false;
60  }
61 
62  @Override
63  public int compareTo(ReportColumn o) {
64  int result = CompareUtil.compare(order, o.getOrder());
65  if(result == 0) {
66  result = CompareUtil.compare(name, o.getName());
67  }
68  return result;
69  }
70 
71  @Override
72  public int hashCode() {
73  return Objects.hash(order, name, regexp);
74  }
75 
76 }
ReportColumn(int order, String name, String regexp[])