forked from Tencent/APIJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogic.java
executable file
·140 lines (113 loc) · 2.73 KB
/
Logic.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*Copyright (C) 2020 THL A29 Limited, a Tencent company. All rights reserved.
This source code is licensed under the Apache License Version 2.0.*/
package apijson.orm;
import apijson.StringUtil;
/**& | !逻辑
* @author Lemon
*/
public class Logic {
public static final int TYPE_OR = 0;
public static final int TYPE_AND = 1;
public static final int TYPE_NOT = 2;
public static final int[] TYPES = {TYPE_OR, TYPE_AND, TYPE_NOT};
public static final String CHAR_OR = "|";
public static final String CHAR_AND = "&";
public static final String CHAR_NOT = "!";
public static final String[] CHARS = {CHAR_OR, CHAR_AND, CHAR_NOT};
public static final String NAME_OR = "OR";
public static final String NAME_AND = "AND";
public static final String NAME_NOT = "NOT";
public static final String[] NAMES = {NAME_OR, NAME_AND, NAME_NOT};
private int type;
private String key;
public Logic() {
super();
}
public Logic(int type) {
this();
this.type = type;
}
public Logic(String key) {
key = StringUtil.getString(key);
int type = getType(key.isEmpty() ? "" : key.substring(key.length() - 1));
if (type >= 0 && type <= 2) {
key = key.substring(0, key.length() - 1);
}
if (type < 0) {
type = 0;
}
setType(type);
setKey(key);
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public boolean isOr() {
return isOr(type);
}
public static boolean isOr(int type) {
return type == TYPE_OR;
}
public boolean isAnd() {
return isAnd(type);
}
public static boolean isAnd(int type) {
return type == TYPE_AND;
}
public boolean isNot() {
return isNot(type);
}
public static boolean isNot(int type) {
return type == TYPE_NOT;
}
public boolean isCorrect() {
return isContain(getType());
}
public static boolean isContain(String s) {
return isContain(getType(s));
}
public static boolean isContain(int type) {
return type >= TYPE_OR && type <= TYPE_NOT;
}
public static int getType(char logicChar) {
return getType(String.valueOf(logicChar));
}
public static int getType(String logicChar) {
int type = -1;
if (logicChar != null && logicChar.length() == 1) {
switch (logicChar) {
case "|":
type = 0;
break;
case "&":
type = 1;
break;
case "!":
type = 2;
break;
}
}
return type;
}
public String getChar() {
return getChar(type);
}
public static String getChar(int type) {
return type < 0 || type >= CHARS.length ? "" : CHARS[type];
}
public String getName() {
return getName(type);
}
public static String getName(int type) {
return type < 0 || type >= NAMES.length ? "" : NAMES[type];
}
}