asterixdb-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cameron Samak (Code Review)" <do-not-re...@asterixdb.incubator.apache.org>
Subject Change in asterixdb[master]: Remove duplicate operator symbol definition
Date Wed, 06 Jul 2016 20:26:38 GMT
Cameron Samak has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/979

Change subject: Remove duplicate operator symbol definition
......................................................................

Remove duplicate operator symbol definition

Change-Id: I3cfcf9a7e131d60a9b97fbc9fae3b762031c8edb
---
M asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/expression/OperatorExpr.java
M asterixdb/asterix-lang-common/src/main/java/org/apache/asterix/lang/common/struct/OperatorType.java
2 files changed, 14 insertions(+), 65 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb refs/changes/79/979/1

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();
+    }
 }

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/979
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I3cfcf9a7e131d60a9b97fbc9fae3b762031c8edb
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Cameron Samak <csamak@apache.org>

Mime
View raw message