Remove duplicate operator symbol definition
Change-Id: I3cfcf9a7e131d60a9b97fbc9fae3b762031c8edb
Reviewed-on: https://asterix-gerrit.ics.uci.edu/979
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OperatorExpr.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OperatorExpr.java
index 8f2374f..bf70df4 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OperatorExpr.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OperatorExpr.java
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
import org.apache.asterix.common.exceptions.AsterixException;
import org.apache.asterix.lang.common.base.AbstractExpression;
@@ -90,71 +91,12 @@
}
public void addOperator(String strOp) {
- switch (strOp) {
- case "or":
- opList.add(OperatorType.OR);
- break;
- case "and":
- opList.add(OperatorType.AND);
- break;
- case "<":
- opList.add(OperatorType.LT);
- break;
- case ">":
- opList.add(OperatorType.GT);
- break;
- case "<=":
- opList.add(OperatorType.LE);
- break;
- case ">=":
- opList.add(OperatorType.GE);
- break;
- case "=":
- opList.add(OperatorType.EQ);
- break;
- case "!=":
- opList.add(OperatorType.NEQ);
- break;
- case "+":
- opList.add(OperatorType.PLUS);
- break;
- case "-":
- opList.add(OperatorType.MINUS);
- break;
- case "*":
- opList.add(OperatorType.MUL);
- break;
- case "/":
- opList.add(OperatorType.DIV);
- break;
- case "%":
- opList.add(OperatorType.MOD);
- break;
- case "^":
- opList.add(OperatorType.CARET);
- break;
- case "idiv":
- opList.add(OperatorType.IDIV);
- break;
- case "~=":
- opList.add(OperatorType.FUZZY_EQ);
- break;
- case "like":
- opList.add(OperatorType.LIKE);
- break;
- case "not_like":
- opList.add(OperatorType.NOT_LIKE);
- break;
- case "in":
- opList.add(OperatorType.IN);
- break;
- case "not_in":
- opList.add(OperatorType.NOT_IN);
- break;
- default:
- throw new UnsupportedOperationException("Unsupported operator: " + strOp);
+ Optional<OperatorType> op = OperatorType.fromSymbol(strOp);
+ if (op.isPresent()) {
+ opList.add(op.get());
+ } else {
+ throw new UnsupportedOperationException("Unsupported operator: " + strOp);
}
-
}
@Override
diff --git a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/struct/OperatorType.java b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/struct/OperatorType.java
index bb15ecd..6e2e3e2 100644
--- a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/struct/OperatorType.java
+++ b/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/struct/OperatorType.java
@@ -18,6 +18,9 @@
*/
package org.apache.asterix.lang.common.struct;
+import java.util.Arrays;
+import java.util.Optional;
+
public enum OperatorType {
OR("or"),
AND("and"),
@@ -43,7 +46,7 @@
private final String symbol;
- private OperatorType(String s) {
+ OperatorType(String s) {
symbol = s;
}
@@ -51,4 +54,8 @@
public String toString() {
return symbol;
}
+
+ public static Optional<OperatorType> fromSymbol(String symbol) {
+ return Arrays.stream(OperatorType.values()).filter(o -> o.symbol.equals(symbol)).findFirst();
+ }
}