-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathSearchOperation.kt
54 lines (51 loc) · 1.24 KB
/
SearchOperation.kt
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
package com.sipios.springsearch
enum class SearchOperation {
EQUALS,
NOT_EQUALS,
GREATER_THAN,
LESS_THAN,
STARTS_WITH,
ENDS_WITH,
CONTAINS,
DOESNT_START_WITH,
DOESNT_END_WITH,
DOESNT_CONTAIN,
GREATER_THAN_EQUALS,
LESS_THAN_EQUALS,
IN_ARRAY,
NOT_IN_ARRAY,
IS,
IS_NOT,
BETWEEN,
NOT_BETWEEN,
;
companion object {
val SIMPLE_OPERATION_SET = arrayOf(":", "!", ">", "<", "~", ">:", "<:")
val ZERO_OR_MORE_REGEX = "*"
val OR_OPERATOR = "OR"
val AND_OPERATOR = "AND"
val LEFT_PARANTHESIS = "("
val RIGHT_PARANTHESIS = ")"
val EMPTY = "EMPTY"
val NULL = "NULL"
/**
* Parse a string into an operation.
*
* @param input operation as string
* @return The matching operation
*/
fun getSimpleOperation(
input: String
): SearchOperation? {
return when (input) {
":" -> EQUALS
"!" -> NOT_EQUALS
">" -> GREATER_THAN
"<" -> LESS_THAN
">:" -> GREATER_THAN_EQUALS
"<:" -> LESS_THAN_EQUALS
else -> null
}
}
}
}