-
Notifications
You must be signed in to change notification settings - Fork 88
/
QueryOperator.java
59 lines (48 loc) · 1.39 KB
/
QueryOperator.java
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
package de.bwaldvogel.mongo.backend;
import java.util.HashMap;
import java.util.Map;
import de.bwaldvogel.mongo.exception.BadValueException;
import de.bwaldvogel.mongo.exception.MongoServerError;
public enum QueryOperator {
IN("$in"),
NOT_IN("$nin"),
NOT("$not"),
NOT_EQUALS("$ne"),
EQUAL("$eq"),
EXISTS("$exists"),
GREATER_THAN_OR_EQUAL("$gte"),
GREATER_THAN("$gt"),
LESS_THAN_OR_EQUAL("$lte"),
LESS_THAN("$lt"),
MOD("$mod"),
SIZE("$size"),
AND("$and"),
OR("$or"),
ALL("$all"),
ELEM_MATCH("$elemMatch"),
TYPE("$type"),
NEAR_SPHERE("$nearSphere"),
GEO_WITHIN("$geoWithin"),
;
private final String value;
QueryOperator(String value) {
this.value = value;
}
public String getValue() {
return value;
}
private static final Map<String, QueryOperator> MAP = new HashMap<>();
static {
for (QueryOperator operator : QueryOperator.values()) {
QueryOperator old = MAP.put(operator.getValue(), operator);
Assert.isNull(old, () -> "Duplicate operator value: " + operator.getValue());
}
}
static QueryOperator fromValue(String value) throws MongoServerError {
QueryOperator operator = MAP.get(value);
if (operator == null) {
throw new BadValueException("unknown operator: " + value);
}
return operator;
}
}