Skip to content

Commit 33b2bc1

Browse files
committed
Added two new filters to statistics generator
1 parent 0a474e2 commit 33b2bc1

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

statistics-generator/statistics-generator-impl/src/main/java/pl/edu/icm/coansys/statisticsgenerator/conf/ComponentsMapping.java

+4
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
import pl.edu.icm.coansys.statisticsgenerator.operationcomponents.CountSummary;
2424
import pl.edu.icm.coansys.statisticsgenerator.operationcomponents.DateRangesPartitioner;
2525
import pl.edu.icm.coansys.statisticsgenerator.operationcomponents.EqualsPartitioner;
26+
import pl.edu.icm.coansys.statisticsgenerator.operationcomponents.FilterContains;
2627
import pl.edu.icm.coansys.statisticsgenerator.operationcomponents.FilterEq;
2728
import pl.edu.icm.coansys.statisticsgenerator.operationcomponents.FilterNotEmpty;
29+
import pl.edu.icm.coansys.statisticsgenerator.operationcomponents.FilterTwoFieldsEqual;
2830
import pl.edu.icm.coansys.statisticsgenerator.operationcomponents.FirstCharsPartitioner;
2931
import pl.edu.icm.coansys.statisticsgenerator.operationcomponents.LastCharsPartitioner;
3032
import pl.edu.icm.coansys.statisticsgenerator.operationcomponents.OperationComponent;
@@ -43,6 +45,8 @@ private ComponentsMapping() {}
4345
static {
4446
mapping.put("EQFILTER", FilterEq.class);
4547
mapping.put("NONEMPTYFILTER", FilterNotEmpty.class);
48+
mapping.put("TWOFIELDSEQFILTER", FilterTwoFieldsEqual.class);
49+
mapping.put("CONTAINSFILTER", FilterContains.class);
4650
mapping.put("EQUALS", EqualsPartitioner.class);
4751
mapping.put("FIRSTCHARS", FirstCharsPartitioner.class);
4852
mapping.put("LASTCHARS", LastCharsPartitioner.class);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* This file is part of CoAnSys project.
3+
* Copyright (c) 2012-2013 ICM-UW
4+
*
5+
* CoAnSys 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+
* CoAnSys 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 CoAnSys. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package pl.edu.icm.coansys.statisticsgenerator.operationcomponents;
20+
21+
import pl.edu.icm.coansys.models.StatisticsProtos;
22+
import pl.edu.icm.coansys.models.StatisticsProtos.KeyValue;
23+
24+
/**
25+
*
26+
* @author Artur Czeczko <a.czeczko@icm.edu.pl>
27+
*/
28+
public class FilterContains implements FilterComponent {
29+
private String fieldName;
30+
private String value;
31+
32+
@Override
33+
public boolean filter(StatisticsProtos.InputEntry entry) {
34+
for (KeyValue kv : entry.getFieldList()) {
35+
if (kv.getKey().equals(fieldName)) {
36+
return kv.getValue().contains(value);
37+
}
38+
}
39+
return false;
40+
}
41+
42+
@Override
43+
public void setup(String... params) {
44+
if (params.length != 2) {
45+
throw new IllegalArgumentException("setup requires 2 parameters: field name and value");
46+
}
47+
fieldName = params[0];
48+
value = params[1];
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* This file is part of CoAnSys project.
3+
* Copyright (c) 2012-2013 ICM-UW
4+
*
5+
* CoAnSys 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+
* CoAnSys 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 CoAnSys. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
19+
package pl.edu.icm.coansys.statisticsgenerator.operationcomponents;
20+
21+
import java.util.ArrayList;
22+
import java.util.List;
23+
import pl.edu.icm.coansys.models.StatisticsProtos;
24+
import pl.edu.icm.coansys.models.StatisticsProtos.KeyValue;
25+
26+
/**
27+
*
28+
* @author Artur Czeczko <a.czeczko@icm.edu.pl>
29+
*/
30+
public class FilterTwoFieldsEqual implements FilterComponent {
31+
32+
private List<String> fieldNames = new ArrayList<String>(2);
33+
34+
@Override
35+
public boolean filter(StatisticsProtos.InputEntry entry) {
36+
String firstKey = null;
37+
String firstValue = null;
38+
39+
for (KeyValue kv : entry.getFieldList()) {
40+
if (fieldNames.contains(kv.getKey()) && !kv.getKey().equals(firstKey)) {
41+
if (firstValue == null) {
42+
firstKey = kv.getKey();
43+
firstValue = kv.getValue();
44+
} else {
45+
return firstValue.equals(kv.getValue());
46+
}
47+
}
48+
}
49+
return false;
50+
}
51+
52+
@Override
53+
public void setup(String... params) {
54+
if (params.length != 2) {
55+
throw new IllegalArgumentException("setup requires 2 parameters: field name and value");
56+
}
57+
fieldNames.add(params[0]);
58+
fieldNames.add(params[1]);
59+
}
60+
}

0 commit comments

Comments
 (0)