asterixdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From buyin...@apache.org
Subject asterixdb git commit: Remove duplicate operator symbol definition
Date Fri, 08 Jul 2016 20:53:54 GMT
Repository: asterixdb
Updated Branches:
  refs/heads/master 29682cf47 -> bd552d8a1


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>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/bd552d8a
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/bd552d8a
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/bd552d8a

Branch: refs/heads/master
Commit: bd552d8a1d6cfcc359b21e1694d9c78a4e06a3ae
Parents: 29682cf
Author: Cameron Samak <csamak@apache.org>
Authored: Wed Jul 6 13:25:45 2016 -0700
Committer: Yingyi Bu <buyingyi@gmail.com>
Committed: Fri Jul 8 13:53:31 2016 -0700

----------------------------------------------------------------------
 .../lang/common/expression/OperatorExpr.java    | 70 ++------------------
 .../lang/common/struct/OperatorType.java        |  9 ++-
 2 files changed, 14 insertions(+), 65 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/bd552d8a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OperatorExpr.java
----------------------------------------------------------------------
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 @@ package org.apache.asterix.lang.common.expression;
 
 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 class OperatorExpr extends AbstractExpression {
     }
 
     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

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/bd552d8a/asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/struct/OperatorType.java
----------------------------------------------------------------------
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 @@ public enum OperatorType {
 
     private final String symbol;
 
-    private OperatorType(String s) {
+    OperatorType(String s) {
         symbol = s;
     }
 
@@ -51,4 +54,8 @@ public enum OperatorType {
     public String toString() {
         return symbol;
     }
+
+    public static Optional<OperatorType> fromSymbol(String symbol) {
+        return Arrays.stream(OperatorType.values()).filter(o -> o.symbol.equals(symbol)).findFirst();
+    }
 }


Mime
View raw message