getCasters() {
- return casters;
- }
@Override
public Criteria visitInput(io.github.ajclopez.mss.QueryParser.InputContext ctx) {
@@ -44,20 +40,21 @@ public Criteria visitOpQuery(io.github.ajclopez.mss.QueryParser.OpQueryContext c
Criteria left = visit(ctx != null ? ctx.left : null);
Criteria right = visit(ctx != null ? ctx.right : null);
+
+ String logicalOperation = null;
- String logicalOperation = ctx != null ? (ctx.logicalOp != null ? ctx.logicalOp.getText() : null ) : null;
-
- if ( logicalOperation == null ) {
- return new Criteria().andOperator(left, right);
+ if (ctx != null && ctx.logicalOp != null ) {
+ logicalOperation = ctx.logicalOp.getText();
}
- switch (LogicalOperation.getLogicalOperation(logicalOperation)) {
- case AND:
- default:
+ if ( logicalOperation == null ) {
return new Criteria().andOperator(left, right);
- case OR:
- return new Criteria().orOperator(left, right);
}
+
+ return switch (LogicalOperation.getLogicalOperation(logicalOperation)) {
+ case OR -> new Criteria().orOperator(left, right);
+ default -> new Criteria().andOperator(left, right);
+ };
}
@Override
diff --git a/src/main/java/io/github/ajclopez/mss/model/Configuration.java b/src/main/java/io/github/ajclopez/mss/model/Configuration.java
index e224b34..b80bf52 100644
--- a/src/main/java/io/github/ajclopez/mss/model/Configuration.java
+++ b/src/main/java/io/github/ajclopez/mss/model/Configuration.java
@@ -3,45 +3,14 @@
import java.util.Map;
/**
- *
* Class used for advanced options [optional].
- *
+ *
*
* - casters: object which map keys to casters ({@code BOOLEAN, NUMBER, PATTERN, DATE, STRING}).
*
- defaultLimit: default value for {@code limit} key.
- *
- maxLimit: maximum value for {@code limit} key.
+ *
- maxLimit: maximum value for {@code limit} key.
*
- *
*/
-public class Configuration {
+public record Configuration(Map casters, Integer defaultLimit, Integer maxLimit) {
- private Map casters;
- private Integer defaultLimit;
- private Integer maxLimit;
-
- /**
- * Creates a new {@link Configuration} with parameters applied.
- *
- * @param casters object which map keys to casters ({@code BOOLEAN, NUMBER, PATTERN, DATE, STRING}).
- * @param defaultLimit default value for {@code limit} key.
- * @param maxLimit maximum value for {@code limit} key.
- */
- public Configuration(Map casters, Integer defaultLimit, Integer maxLimit) {
- this.casters = casters;
- this.defaultLimit = defaultLimit;
- this.maxLimit = maxLimit;
- }
-
- public Map getCasters() {
- return casters;
- }
-
- public Integer getDefaultLimit() {
- return defaultLimit;
- }
-
- public Integer getMaxLimit() {
- return maxLimit;
- }
-
}
diff --git a/src/main/java/io/github/ajclopez/mss/model/KeySearchOperation.java b/src/main/java/io/github/ajclopez/mss/model/KeySearchOperation.java
index 8a033ad..74c28fd 100644
--- a/src/main/java/io/github/ajclopez/mss/model/KeySearchOperation.java
+++ b/src/main/java/io/github/ajclopez/mss/model/KeySearchOperation.java
@@ -5,20 +5,14 @@ public enum KeySearchOperation {
SKIP, LIMIT, SORT, FIELDS, FILTER, DEFAULT;
public static KeySearchOperation getKeyOperation(String input) {
- switch (input) {
- case "skip":
- return SKIP;
- case "limit":
- return LIMIT;
- case "sort":
- return SORT;
- case "fields":
- return FIELDS;
- case "filter":
- return FILTER;
- default:
- return DEFAULT;
- }
+ return switch (input) {
+ case "skip" -> SKIP;
+ case "limit" -> LIMIT;
+ case "sort" -> SORT;
+ case "fields" -> FIELDS;
+ case "filter" -> FILTER;
+ default -> DEFAULT;
+ };
}
}
diff --git a/src/main/java/io/github/ajclopez/mss/model/LogicalOperation.java b/src/main/java/io/github/ajclopez/mss/model/LogicalOperation.java
index ebe0299..e1b83c2 100644
--- a/src/main/java/io/github/ajclopez/mss/model/LogicalOperation.java
+++ b/src/main/java/io/github/ajclopez/mss/model/LogicalOperation.java
@@ -5,16 +5,11 @@ public enum LogicalOperation {
AND, OR;
public static LogicalOperation getLogicalOperation(String input) {
- switch (input) {
- case "AND":
- case "and":
- return AND;
- case "OR":
- case "or":
- return OR;
- default:
- return null;
- }
+ return switch (input) {
+ case "AND", "and" -> AND;
+ case "OR", "or" -> OR;
+ default -> null;
+ };
}
}
diff --git a/src/main/java/io/github/ajclopez/mss/model/SearchOperation.java b/src/main/java/io/github/ajclopez/mss/model/SearchOperation.java
index 4bc4ec9..308a63b 100644
--- a/src/main/java/io/github/ajclopez/mss/model/SearchOperation.java
+++ b/src/main/java/io/github/ajclopez/mss/model/SearchOperation.java
@@ -5,23 +5,15 @@ public enum SearchOperation {
EQUAL, NOT_EQUAL, GREATER_THAN, GREATER_THAN_EQUAL, LESS_THAN, LESS_THAN_EQUAL, EXISTS;
public static SearchOperation getOperation(String input) {
- switch (input) {
- case "=":
- return EQUAL;
- case "!=":
- return NOT_EQUAL;
- case ">":
- return GREATER_THAN;
- case ">=":
- return GREATER_THAN_EQUAL;
- case "<":
- return LESS_THAN;
- case "<=":
- return LESS_THAN_EQUAL;
- case "!":
- default:
- return EXISTS;
- }
+ return switch (input) {
+ case "=" -> EQUAL;
+ case "!=" -> NOT_EQUAL;
+ case ">" -> GREATER_THAN;
+ case ">=" -> GREATER_THAN_EQUAL;
+ case "<" -> LESS_THAN;
+ case "<=" -> LESS_THAN_EQUAL;
+ default -> EXISTS;
+ };
}
}
diff --git a/src/main/java/io/github/ajclopez/mss/model/SortSearchOperation.java b/src/main/java/io/github/ajclopez/mss/model/SortSearchOperation.java
index a264fec..21620aa 100644
--- a/src/main/java/io/github/ajclopez/mss/model/SortSearchOperation.java
+++ b/src/main/java/io/github/ajclopez/mss/model/SortSearchOperation.java
@@ -5,14 +5,10 @@ public enum SortSearchOperation {
ASC, DESC;
public static SortSearchOperation getSortOperation(String input) {
- switch (input) {
- case "+":
- case " ":
- default:
- return ASC;
- case "-":
- return DESC;
- }
+ return switch (input) {
+ case "-" -> DESC;
+ default -> ASC;
+ };
}
}
diff --git a/src/main/java/io/github/ajclopez/mss/parser/QueryParser.java b/src/main/java/io/github/ajclopez/mss/parser/QueryParser.java
index a26637a..dc6e581 100644
--- a/src/main/java/io/github/ajclopez/mss/parser/QueryParser.java
+++ b/src/main/java/io/github/ajclopez/mss/parser/QueryParser.java
@@ -44,7 +44,7 @@ private QueryParser() {
*/
public static List parse(String query, Map casters) {
- List criterias = new ArrayList();
+ List criterias = new ArrayList<>();
for ( String condition : query.split("&") ) {
criterias.add(criteriaParser(condition, casters));
@@ -97,7 +97,7 @@ public static Object parseValue(String value, CastType caster) {
case BOOLEAN:
return Boolean.parseBoolean(value);
case DATE:
- return parseLocalDateTime(value, DATE_FORMAT);
+ return parseLocalDateTime(value);
case NUMBER:
try {
return NumberFormat.getInstance().parse(value);
@@ -128,7 +128,7 @@ private static Object parseValue(String value) {
String[] parts = value.split(",");
if ( parts.length > 1 ) {
- List