Skip to content

Commit 7105ebe

Browse files
Java version upgraded to 1.8 from 1.7 (#2)
* Java version upgraded to 1.8
1 parent 1b9fd6e commit 7105ebe

33 files changed

+668
-356
lines changed

README.md

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,28 @@ This library helps you for executing to created validations with [jQuery QueryBu
66
You can execute to generated validations as simply.
77
Generated validation text/json should be convert to `Map` for using executions. `Gson` dependency is good choice for converting to `Map` from string.
88

9-
```xml
10-
<dependency>
11-
<groupId>com.google.code.gson</groupId>
12-
<artifactId>gson</artifactId>
13-
<version>2.8.0</version>
14-
</dependency>
15-
```
16-
179

1810
#### Example Validation Json
1911
```js
2012
// String validationString=..
21-
{
22-
"condition":"OR",
23-
"rules":[
24-
{
25-
"field":"number",
26-
"type":"integer",
27-
"operator":"equal",
28-
"value":"7"
29-
},
30-
{
31-
"field":"number",
32-
"type":"integer",
33-
"operator":"equal",
34-
"value":"8"
35-
}
36-
],
37-
"not":false
13+
{
14+
"condition":"OR",
15+
"rules":[
16+
{
17+
"field":"number",
18+
"type":"integer",
19+
"operator":"equal",
20+
"value":"7"
21+
},
22+
{
23+
"field":"number",
24+
"type":"integer",
25+
"operator":"equal",
26+
"value":"8"
3827
}
28+
],
29+
"not":false
30+
}
3931
```
4032
#### Using Validation Execution
4133
```java
@@ -52,7 +44,7 @@ ValidationGroup validationGroup = new ValidationGroup(map);
5244

5345
//execute validation
5446
boolean result=validationGroup.execute(yourData)
55-
assertTrue(result);// result will `true` according to example
47+
assertTrue(result);// true
5648

5749

5850
```

dist/JQueryBuilder-1.0.0.jar

2.02 KB
Binary file not shown.

pom.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45

56
<groupId>com.ibrahim</groupId>
6-
<artifactId>JQueryBuilder</artifactId>
7+
<artifactId>QueryBuilderResolver</artifactId>
78
<version>1.0.0</version>
89
<packaging>jar</packaging>
910

10-
<name>JavaResolver for jQuery QueryBuilder</name>
11-
<url>http://maven.apache.org</url>
12-
11+
<name>QueryBuilderResolver</name>
12+
<description>JavaResolver for jQuery QueryBuilder</description>
1313
<properties>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
16-
<maven.compiler.source>1.7</maven.compiler.source>
17-
<maven.compiler.target>1.7</maven.compiler.target>
16+
<maven.compiler.source>1.8</maven.compiler.source>
17+
<maven.compiler.target>1.8</maven.compiler.target>
1818
</properties>
1919
<dependencies>
2020
<dependency>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.jquerybuilder.operation;
2+
3+
public interface BinaryExecutor {
4+
public boolean apply(Object argument1, Object argument2);
5+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.jquerybuilder.operation;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
import com.jquerybuilder.operation.function.BeginsWith;
6+
import com.jquerybuilder.operation.function.Between;
7+
import com.jquerybuilder.operation.function.Contains;
8+
import com.jquerybuilder.operation.function.EndsWith;
9+
import com.jquerybuilder.operation.function.Equal;
10+
import com.jquerybuilder.operation.function.Greater;
11+
import com.jquerybuilder.operation.function.GreaterOrEqual;
12+
import com.jquerybuilder.operation.function.In;
13+
import com.jquerybuilder.operation.function.IsEmpty;
14+
import com.jquerybuilder.operation.function.IsNotEmpty;
15+
import com.jquerybuilder.operation.function.IsNotNull;
16+
import com.jquerybuilder.operation.function.IsNull;
17+
import com.jquerybuilder.operation.function.Less;
18+
import com.jquerybuilder.operation.function.LessOrEqual;
19+
import com.jquerybuilder.operation.function.NotBeginsWith;
20+
import com.jquerybuilder.operation.function.NotBetween;
21+
import com.jquerybuilder.operation.function.NotContains;
22+
import com.jquerybuilder.operation.function.NotEndsWith;
23+
import com.jquerybuilder.operation.function.NotEqual;
24+
import com.jquerybuilder.operation.function.NotIn;
25+
26+
public class Operation {
27+
private static Map<String, OperationExecutor> operationMap = new HashMap<>();
28+
public static final Less Less = new Less();
29+
public static final LessOrEqual LessOrEqual = new LessOrEqual();
30+
public static final Greater Greater = new Greater();
31+
public static final GreaterOrEqual GreaterOrEqual = new GreaterOrEqual();
32+
public static final Between Between = new Between();
33+
public static final NotBetween NotBetween = new NotBetween();
34+
public static final Equal Equal = new Equal();
35+
public static final NotEqual NotEqual = new NotEqual();
36+
public static final Contains Contains = new Contains();
37+
public static final NotContains NotContains = new NotContains();
38+
public static final In In = new In();
39+
public static final NotIn NotIn = new NotIn();
40+
public static final IsNull IsNull = new IsNull();
41+
public static final IsNotNull IsNotNull = new IsNotNull();
42+
public static final BeginsWith BeginsWith = new BeginsWith();
43+
public static final NotBeginsWith NotBeginsWith = new NotBeginsWith();
44+
public static final EndsWith EndsWith = new EndsWith();
45+
public static final NotEndsWith NotEndsWith = new NotEndsWith();
46+
public static final IsEmpty IsEmpty = new IsEmpty();
47+
public static final IsNotEmpty IsNotEmpty = new IsNotEmpty();
48+
49+
static {
50+
operationMap.put("less", Less);
51+
operationMap.put("less_or_equal", LessOrEqual);
52+
operationMap.put("greater", Greater);
53+
operationMap.put("greater_or_equal", GreaterOrEqual);
54+
operationMap.put("between", Between);
55+
operationMap.put("not_between", NotBetween);
56+
operationMap.put("equal", Equal);
57+
operationMap.put("not_equal", NotEqual);
58+
operationMap.put("contains", Contains);
59+
operationMap.put("not_contains", NotContains);
60+
operationMap.put("in", In);
61+
operationMap.put("not_in", NotIn);
62+
operationMap.put("is_null", IsNull);
63+
operationMap.put("is_not_null", IsNotNull);
64+
operationMap.put("begins_with", BeginsWith);
65+
operationMap.put("not_begins_with", NotBeginsWith);
66+
operationMap.put("ends_with", EndsWith);
67+
operationMap.put("not_ends_with", NotEndsWith);
68+
operationMap.put("is_empty", IsEmpty);
69+
operationMap.put("is_not_empty", IsNotEmpty);
70+
71+
}
72+
73+
public static boolean apply(String operation, Object v1) {
74+
Object operator = operationMap.get(operation);
75+
return ((UnaryExecutor) operator).apply(v1);
76+
}
77+
78+
public static boolean apply(String operation, Object v1, Object v2) {
79+
Object operator = operationMap.get(operation);
80+
return ((BinaryExecutor) operator).apply(v1, v2);
81+
}
82+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.jquerybuilder.operation;
2+
3+
import java.util.List;
4+
5+
public class OperationExecutor {
6+
7+
public Long number(Object argument) {
8+
return argument == null || "".equals(argument) ? 0 : Long.parseLong(String.valueOf(argument));
9+
}
10+
11+
public List<?> list(Object argument) {
12+
return argument == null ? List.of() : (List<?>) argument;
13+
}
14+
15+
protected String string(Object argument) {
16+
return argument == null ? "" : String.valueOf(argument);
17+
}
18+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.jquerybuilder.operation;
2+
3+
public interface UnaryExecutor {
4+
public boolean apply(Object argument);
5+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.jquerybuilder.operation.function;
2+
3+
import com.jquerybuilder.operation.OperationExecutor;
4+
import com.jquerybuilder.operation.BinaryExecutor;
5+
6+
public class BeginsWith extends OperationExecutor implements BinaryExecutor {
7+
8+
@Override
9+
public boolean apply(Object term, Object text) {
10+
return string(text).toLowerCase().startsWith(string(term).toLowerCase());
11+
}
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.jquerybuilder.operation.function;
2+
3+
import java.util.List;
4+
import com.jquerybuilder.operation.OperationExecutor;
5+
import com.jquerybuilder.operation.BinaryExecutor;
6+
7+
public class Between extends OperationExecutor implements BinaryExecutor {
8+
@Override
9+
public boolean apply(Object number, Object range) {
10+
try {
11+
List<?> list = list(range);
12+
long i1 = number(number);
13+
long i2 = Long.parseLong(list.get(0).toString());
14+
long i3 = Long.parseLong(list.get(1).toString());
15+
return i2 > i3 ? i1 > i3 && i1 < i2 : i1 > i2 && i1 < i3;
16+
} catch (Exception e) {
17+
return false;
18+
}
19+
}
20+
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.jquerybuilder.operation.function;
2+
3+
import com.jquerybuilder.operation.OperationExecutor;
4+
import com.jquerybuilder.operation.BinaryExecutor;
5+
6+
public class Contains extends OperationExecutor implements BinaryExecutor {
7+
@Override
8+
public boolean apply(Object text, Object term) {
9+
try {
10+
return string(text).contains(string(term));
11+
} catch (Exception e) {
12+
return false;
13+
}
14+
}
15+
}

0 commit comments

Comments
 (0)