-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java version upgraded to 1.8 from 1.7 (#2)
* Java version upgraded to 1.8
- Loading branch information
1 parent
1b9fd6e
commit 7105ebe
Showing
33 changed files
with
668 additions
and
356 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/java/com/jquerybuilder/operation/BinaryExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.jquerybuilder.operation; | ||
|
||
public interface BinaryExecutor { | ||
public boolean apply(Object argument1, Object argument2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.jquerybuilder.operation; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import com.jquerybuilder.operation.function.BeginsWith; | ||
import com.jquerybuilder.operation.function.Between; | ||
import com.jquerybuilder.operation.function.Contains; | ||
import com.jquerybuilder.operation.function.EndsWith; | ||
import com.jquerybuilder.operation.function.Equal; | ||
import com.jquerybuilder.operation.function.Greater; | ||
import com.jquerybuilder.operation.function.GreaterOrEqual; | ||
import com.jquerybuilder.operation.function.In; | ||
import com.jquerybuilder.operation.function.IsEmpty; | ||
import com.jquerybuilder.operation.function.IsNotEmpty; | ||
import com.jquerybuilder.operation.function.IsNotNull; | ||
import com.jquerybuilder.operation.function.IsNull; | ||
import com.jquerybuilder.operation.function.Less; | ||
import com.jquerybuilder.operation.function.LessOrEqual; | ||
import com.jquerybuilder.operation.function.NotBeginsWith; | ||
import com.jquerybuilder.operation.function.NotBetween; | ||
import com.jquerybuilder.operation.function.NotContains; | ||
import com.jquerybuilder.operation.function.NotEndsWith; | ||
import com.jquerybuilder.operation.function.NotEqual; | ||
import com.jquerybuilder.operation.function.NotIn; | ||
|
||
public class Operation { | ||
private static Map<String, OperationExecutor> operationMap = new HashMap<>(); | ||
public static final Less Less = new Less(); | ||
public static final LessOrEqual LessOrEqual = new LessOrEqual(); | ||
public static final Greater Greater = new Greater(); | ||
public static final GreaterOrEqual GreaterOrEqual = new GreaterOrEqual(); | ||
public static final Between Between = new Between(); | ||
public static final NotBetween NotBetween = new NotBetween(); | ||
public static final Equal Equal = new Equal(); | ||
public static final NotEqual NotEqual = new NotEqual(); | ||
public static final Contains Contains = new Contains(); | ||
public static final NotContains NotContains = new NotContains(); | ||
public static final In In = new In(); | ||
public static final NotIn NotIn = new NotIn(); | ||
public static final IsNull IsNull = new IsNull(); | ||
public static final IsNotNull IsNotNull = new IsNotNull(); | ||
public static final BeginsWith BeginsWith = new BeginsWith(); | ||
public static final NotBeginsWith NotBeginsWith = new NotBeginsWith(); | ||
public static final EndsWith EndsWith = new EndsWith(); | ||
public static final NotEndsWith NotEndsWith = new NotEndsWith(); | ||
public static final IsEmpty IsEmpty = new IsEmpty(); | ||
public static final IsNotEmpty IsNotEmpty = new IsNotEmpty(); | ||
|
||
static { | ||
operationMap.put("less", Less); | ||
operationMap.put("less_or_equal", LessOrEqual); | ||
operationMap.put("greater", Greater); | ||
operationMap.put("greater_or_equal", GreaterOrEqual); | ||
operationMap.put("between", Between); | ||
operationMap.put("not_between", NotBetween); | ||
operationMap.put("equal", Equal); | ||
operationMap.put("not_equal", NotEqual); | ||
operationMap.put("contains", Contains); | ||
operationMap.put("not_contains", NotContains); | ||
operationMap.put("in", In); | ||
operationMap.put("not_in", NotIn); | ||
operationMap.put("is_null", IsNull); | ||
operationMap.put("is_not_null", IsNotNull); | ||
operationMap.put("begins_with", BeginsWith); | ||
operationMap.put("not_begins_with", NotBeginsWith); | ||
operationMap.put("ends_with", EndsWith); | ||
operationMap.put("not_ends_with", NotEndsWith); | ||
operationMap.put("is_empty", IsEmpty); | ||
operationMap.put("is_not_empty", IsNotEmpty); | ||
|
||
} | ||
|
||
public static boolean apply(String operation, Object v1) { | ||
Object operator = operationMap.get(operation); | ||
return ((UnaryExecutor) operator).apply(v1); | ||
} | ||
|
||
public static boolean apply(String operation, Object v1, Object v2) { | ||
Object operator = operationMap.get(operation); | ||
return ((BinaryExecutor) operator).apply(v1, v2); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/jquerybuilder/operation/OperationExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.jquerybuilder.operation; | ||
|
||
import java.util.List; | ||
|
||
public class OperationExecutor { | ||
|
||
public Long number(Object argument) { | ||
return argument == null || "".equals(argument) ? 0 : Long.parseLong(String.valueOf(argument)); | ||
} | ||
|
||
public List<?> list(Object argument) { | ||
return argument == null ? List.of() : (List<?>) argument; | ||
} | ||
|
||
protected String string(Object argument) { | ||
return argument == null ? "" : String.valueOf(argument); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.jquerybuilder.operation; | ||
|
||
public interface UnaryExecutor { | ||
public boolean apply(Object argument); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/jquerybuilder/operation/function/BeginsWith.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.jquerybuilder.operation.function; | ||
|
||
import com.jquerybuilder.operation.OperationExecutor; | ||
import com.jquerybuilder.operation.BinaryExecutor; | ||
|
||
public class BeginsWith extends OperationExecutor implements BinaryExecutor { | ||
|
||
@Override | ||
public boolean apply(Object term, Object text) { | ||
return string(text).toLowerCase().startsWith(string(term).toLowerCase()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/jquerybuilder/operation/function/Between.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.jquerybuilder.operation.function; | ||
|
||
import java.util.List; | ||
import com.jquerybuilder.operation.OperationExecutor; | ||
import com.jquerybuilder.operation.BinaryExecutor; | ||
|
||
public class Between extends OperationExecutor implements BinaryExecutor { | ||
@Override | ||
public boolean apply(Object number, Object range) { | ||
try { | ||
List<?> list = list(range); | ||
long i1 = number(number); | ||
long i2 = Long.parseLong(list.get(0).toString()); | ||
long i3 = Long.parseLong(list.get(1).toString()); | ||
return i2 > i3 ? i1 > i3 && i1 < i2 : i1 > i2 && i1 < i3; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/jquerybuilder/operation/function/Contains.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.jquerybuilder.operation.function; | ||
|
||
import com.jquerybuilder.operation.OperationExecutor; | ||
import com.jquerybuilder.operation.BinaryExecutor; | ||
|
||
public class Contains extends OperationExecutor implements BinaryExecutor { | ||
@Override | ||
public boolean apply(Object text, Object term) { | ||
try { | ||
return string(text).contains(string(term)); | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/com/jquerybuilder/operation/function/EndsWith.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.jquerybuilder.operation.function; | ||
|
||
import com.jquerybuilder.operation.OperationExecutor; | ||
import com.jquerybuilder.operation.BinaryExecutor; | ||
|
||
public class EndsWith extends OperationExecutor implements BinaryExecutor { | ||
|
||
@Override | ||
public boolean apply(Object term, Object text) { | ||
return string(text).toLowerCase().endsWith(string(term).toLowerCase()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/jquerybuilder/operation/function/Equal.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.jquerybuilder.operation.function; | ||
|
||
import com.jquerybuilder.operation.OperationExecutor; | ||
import com.jquerybuilder.operation.BinaryExecutor; | ||
|
||
public class Equal extends OperationExecutor implements BinaryExecutor { | ||
@Override | ||
public boolean apply(Object argument1, Object argument2) { | ||
try { | ||
return (argument1 == null && argument2 == null) || argument1.equals(argument2); | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/jquerybuilder/operation/function/Greater.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.jquerybuilder.operation.function; | ||
|
||
import com.jquerybuilder.operation.BinaryExecutor; | ||
import com.jquerybuilder.operation.OperationExecutor; | ||
|
||
public class Greater extends OperationExecutor implements BinaryExecutor { | ||
@Override | ||
public boolean apply(Object greater, Object less) { | ||
try { | ||
long i1 = number(greater); | ||
long i2 = number(less); | ||
return i1 > i2; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/jquerybuilder/operation/function/GreaterOrEqual.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.jquerybuilder.operation.function; | ||
|
||
import com.jquerybuilder.operation.BinaryExecutor; | ||
import com.jquerybuilder.operation.OperationExecutor; | ||
|
||
public class GreaterOrEqual extends OperationExecutor implements BinaryExecutor { | ||
@Override | ||
public boolean apply(Object greatherOrEqual, Object less) { | ||
try { | ||
long i1 = number(greatherOrEqual); | ||
long i2 = number(less); | ||
return i1 >= i2; | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/com/jquerybuilder/operation/function/In.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.jquerybuilder.operation.function; | ||
|
||
import com.jquerybuilder.operation.OperationExecutor; | ||
import com.jquerybuilder.operation.BinaryExecutor; | ||
|
||
public class In extends OperationExecutor implements BinaryExecutor { | ||
|
||
@Override | ||
public boolean apply(Object arg, Object list) { | ||
try { | ||
return list(list).contains(arg); | ||
} catch (Exception e) { | ||
return false; | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/jquerybuilder/operation/function/IsEmpty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.jquerybuilder.operation.function; | ||
|
||
import java.util.List; | ||
import com.jquerybuilder.operation.UnaryExecutor; | ||
import com.jquerybuilder.operation.OperationExecutor; | ||
|
||
public class IsEmpty extends OperationExecutor implements UnaryExecutor { | ||
@Override | ||
public boolean apply(Object argument) { | ||
try { | ||
if (argument == null) { | ||
return false; | ||
} | ||
if (argument instanceof List) { | ||
List<?> list = list(argument); | ||
return list == null || list.isEmpty(); | ||
} else if (argument instanceof String) { | ||
return "".equals(argument); | ||
} | ||
} catch (Exception e) { | ||
} | ||
return false; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/jquerybuilder/operation/function/IsNotEmpty.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.jquerybuilder.operation.function; | ||
|
||
import java.util.List; | ||
import com.jquerybuilder.operation.UnaryExecutor; | ||
import com.jquerybuilder.operation.OperationExecutor; | ||
|
||
public class IsNotEmpty extends OperationExecutor implements UnaryExecutor { | ||
@Override | ||
public boolean apply(Object argument) { | ||
try { | ||
if (argument instanceof List) { | ||
List<?> list = list(argument); | ||
return list != null && !list.isEmpty(); | ||
} else if (argument instanceof String) { | ||
return !"".equals(argument); | ||
} | ||
} catch (Exception e) { | ||
} | ||
return false; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/jquerybuilder/operation/function/IsNotNull.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.jquerybuilder.operation.function; | ||
|
||
import com.jquerybuilder.operation.UnaryExecutor; | ||
import com.jquerybuilder.operation.OperationExecutor; | ||
|
||
public class IsNotNull extends OperationExecutor implements UnaryExecutor { | ||
@Override | ||
public boolean apply(Object argument) { | ||
return argument != null; | ||
} | ||
} |
Oops, something went wrong.