BrightSide Workbench Full Report + Source Code
ViewSets.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.view;
19 
20 import java.util.HashSet;
21 import java.util.Set;
22 import org.turro.financials.entity.RegisterView;
23 import org.turro.financials.model.register.ViewWrapper;
24 import org.turro.util.PhraseBuilder;
25 
30 public class ViewSets {
31 
32  private Set<RegisterView> groupA, groupB;
33 
34  public ViewSets() {
35  groupA = new HashSet<RegisterView>();
36  groupB = new HashSet<RegisterView>();
37  groupA.add(ViewWrapper.getFormalView());
38  }
39 
40  public Set<RegisterView> getGroupA() {
41  return groupA;
42  }
43 
44  public void setGroupA(Set<RegisterView> groupA) {
45  this.groupA.clear();
46  this.groupA.addAll(groupA);
47  }
48 
49  public Set<RegisterView> getGroupB() {
50  return groupB;
51  }
52 
53  public void setGroupB(Set<RegisterView> groupB) {
54  this.groupB.clear();
55  this.groupB.addAll(groupB);
56  }
57 
58  public String getStringFilter() {
59  PhraseBuilder pb = new PhraseBuilder();
60  for(RegisterView v : groupA) {
61  pb.addWord(v.getName());
62  pb.addPendingSeparator(",");
63  }
64  if(!groupB.isEmpty()) {
65  pb.cancelSeparator();
66  pb.addWord("[vs.]");
67  for(RegisterView v : groupB) {
68  pb.addWord(v.getName());
69  pb.addPendingSeparator(",");
70  }
71  }
72  return pb.toString();
73  }
74 
75  public String getSqlWhereAB(String field) {
76  PhraseBuilder pb = new PhraseBuilder();
77  if(!groupA.isEmpty()) {
78  pb.addWord("and (" + field + " in (");
79  for(RegisterView rv : groupA) {
80  pb.addPendingSeparator(",");
81  pb.addWord(rv.getId() + "");
82  }
83  pb.cancelSeparator();
84  pb.addWord(")");
85  if(!groupB.isEmpty()) {
86  pb.addWord("or " + field + " in (");
87  for(RegisterView rv : groupB) {
88  pb.addPendingSeparator(",");
89  pb.addWord(rv.getId() + "");
90  }
91  pb.cancelSeparator();
92  pb.addWord(")");
93  }
94  pb.addWord(")");
95  }
96  return pb.toString();
97  }
98 
99  public String getSqlWhereA(String field) {
100  PhraseBuilder pb = new PhraseBuilder();
101  if(!groupA.isEmpty()) {
102  pb.addWord("and " + field + " in (");
103  for(RegisterView rv : groupA) {
104  pb.addPendingSeparator(",");
105  pb.addWord(rv.getId() + "");
106  }
107  pb.cancelSeparator();
108  pb.addWord(")");
109  } else {
110  pb.addWord("and 1=2");
111  }
112  return pb.toString();
113  }
114 
115  public String getSqlWhereB(String field) {
116  PhraseBuilder pb = new PhraseBuilder();
117  if(!groupB.isEmpty()) {
118  pb.addWord("and " + field + " in (");
119  for(RegisterView rv : groupB) {
120  pb.addPendingSeparator(",");
121  pb.addWord(rv.getId() + "");
122  }
123  pb.cancelSeparator();
124  pb.addWord(")");
125  } else {
126  pb.addWord("and 1=2");
127  }
128  return pb.toString();
129  }
130 
131 }
void setGroupB(Set< RegisterView > groupB)
Definition: ViewSets.java:53
Set< RegisterView > getGroupA()
Definition: ViewSets.java:40
String getSqlWhereA(String field)
Definition: ViewSets.java:99
String getSqlWhereAB(String field)
Definition: ViewSets.java:75
Set< RegisterView > getGroupB()
Definition: ViewSets.java:49
String getSqlWhereB(String field)
Definition: ViewSets.java:115
void setGroupA(Set< RegisterView > groupA)
Definition: ViewSets.java:44