Repository navigation
Expand file tree
/
Copy pathFilter.java
More file actions
64 lines (51 loc) · 1.38 KB
/
Copy pathFilter.java
File metadata and controls
64 lines (51 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package io.getstream.core.options;
import com.google.common.collect.Lists;
import io.getstream.core.http.Request;
import java.util.List;
public final class Filter implements RequestOption {
enum OpType {
ID_GREATER_THEN_OR_EQUAL("id_gte"),
ID_GREATER_THEN("id_gt"),
ID_LESS_THEN_OR_EQUAL("id_lte"),
ID_LESS_THEN("id_lt");
private String operator;
OpType(String operator) {
this.operator = operator;
}
@Override
public String toString() {
return operator;
}
}
private static final class OpEntry {
String type;
String value;
OpEntry(OpType type, String value) {
this.type = type.toString();
this.value = value;
}
}
private final List<OpEntry> ops = Lists.newArrayList();
public Filter idGreaterThan(String id) {
ops.add(new OpEntry(OpType.ID_GREATER_THEN, id));
return this;
}
public Filter idGreaterThanEqual(String id) {
ops.add(new OpEntry(OpType.ID_GREATER_THEN_OR_EQUAL, id));
return this;
}
public Filter idLessThan(String id) {
ops.add(new OpEntry(OpType.ID_LESS_THEN, id));
return this;
}
public Filter idLessThanEqual(String id) {
ops.add(new OpEntry(OpType.ID_LESS_THEN_OR_EQUAL, id));
return this;
}
@Override
public void apply(Request.Builder builder) {
for (OpEntry op : ops) {
builder.addQueryParameter(op.type, op.value);
}
}
}