Repository: olingo-odata4
Updated Branches:
  refs/heads/master 08ffd2019 -> b376959f9


[OLINGO-713] $filter Tutorial - some minor refactorings


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

Branch: refs/heads/master
Commit: b376959f9f12c476a04a9d34e238312087f9d349
Parents: 08ffd20
Author: Christian Holzer <[email protected]>
Authored: Mon Aug 24 14:57:14 2015 +0200
Committer: Christian Holzer <[email protected]>
Committed: Mon Aug 24 14:57:14 2015 +0200

----------------------------------------------------------------------
 .../service/FilterExpressionVisitor.java        | 63 +++++++-------------
 samples/tutorials/pom.xml                       |  1 +
 2 files changed, 22 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b376959f/samples/tutorials/p7_queryoptions-f/src/main/java/myservice/mynamespace/service/FilterExpressionVisitor.java
----------------------------------------------------------------------
diff --git 
a/samples/tutorials/p7_queryoptions-f/src/main/java/myservice/mynamespace/service/FilterExpressionVisitor.java
 
b/samples/tutorials/p7_queryoptions-f/src/main/java/myservice/mynamespace/service/FilterExpressionVisitor.java
index 7550497..5a9af92 100644
--- 
a/samples/tutorials/p7_queryoptions-f/src/main/java/myservice/mynamespace/service/FilterExpressionVisitor.java
+++ 
b/samples/tutorials/p7_queryoptions-f/src/main/java/myservice/mynamespace/service/FilterExpressionVisitor.java
@@ -121,47 +121,26 @@ public class FilterExpressionVisitor implements 
ExpressionVisitor<Object> {
          //   - Boolean operations like and, or are allowed on Edm.Boolean
          // A detailed explanation can be found in OData Version 4.0 Part 2: 
URL Conventions 
          
-    switch (operator) {
-    
-    // Arithmetic operations
-    case ADD:
-      /** Fall through **/
-    case MOD:
-      /** Fall through **/
-    case MUL:
-      /** Fall through **/
-    case DIV:
-      /** Fall through **/
-    case SUB:
+    if (operator == BinaryOperatorKind.ADD
+        || operator == BinaryOperatorKind.MOD
+        || operator == BinaryOperatorKind.MUL
+        || operator == BinaryOperatorKind.DIV
+        || operator == BinaryOperatorKind.SUB) {
       return evaluateArithmeticOperation(operator, left, right);
-
-    // Logical operations
-    case EQ:
-      /** Fall through **/
-    case NE:
-      /** Fall through **/
-    case GE:
-      /** Fall through **/
-    case GT:
-      /** Fall through **/
-    case LE:
-      /** Fall through **/
-    case LT:
-      return evaluateLogicalOperation(operator, left, right);
-      
-    // Boolean operations
-    case AND:
-      /** Fall through **/
-    case OR:
+    } else if (operator == BinaryOperatorKind.EQ
+        || operator == BinaryOperatorKind.NE
+        || operator == BinaryOperatorKind.GE
+        || operator == BinaryOperatorKind.GT
+        || operator == BinaryOperatorKind.LE
+        || operator == BinaryOperatorKind.LT) {
+      return evaluateComparisonOperation(operator, left, right);
+    } else if (operator == BinaryOperatorKind.AND
+        || operator == BinaryOperatorKind.OR) {
       return evaluateBooleanOperation(operator, left, right);
-    
-    case HAS:
-      // Has operation is not supported. We do not use enums in our service.
-      /** fall through **/
-    default:
-      throw new ODataApplicationException("Binary operation " + 
operator.name() + " is not implemented", 
+         } else {
+           throw new ODataApplicationException("Binary operation " + 
operator.name() + " is not implemented", 
           HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ENGLISH);
-    }
+         }
   }
 
        private Object evaluateBooleanOperation(BinaryOperatorKind operator, 
Object left, Object right)
@@ -186,12 +165,12 @@ public class FilterExpressionVisitor implements 
ExpressionVisitor<Object> {
        }
 
   @SuppressWarnings("unchecked")
-  private Object evaluateLogicalOperation(BinaryOperatorKind operator, Object 
left, Object right) 
+  private Object evaluateComparisonOperation(BinaryOperatorKind operator, 
Object left, Object right) 
       throws ODataApplicationException {
     
     // All types in our tutorial supports all logical operations, but we have 
to make sure that the types are equals
     if(left.getClass().equals(right.getClass())) {
-      // Luckily all used types String, Boolean and also Integer supports the 
interface Comparable
+      // Luckily all used types String, Boolean and also Integer support the 
interface Comparable
       // TODO: Is this OK? Otherwise we can infer generic arguments after 
using an if statement
       @SuppressWarnings("rawtypes")
       int result = ((Comparable) left).compareTo(right);
@@ -212,7 +191,7 @@ public class FilterExpressionVisitor implements 
ExpressionVisitor<Object> {
       }
       
     } else {
-      throw new ODataApplicationException("Comparision needs to equal types", 
+      throw new ODataApplicationException("Comparision needs two equal types", 
           HttpStatusCode.BAD_REQUEST.getStatusCode(), Locale.ENGLISH);
     }
   }
@@ -220,7 +199,7 @@ public class FilterExpressionVisitor implements 
ExpressionVisitor<Object> {
   private Object evaluateArithmeticOperation(BinaryOperatorKind operator, 
Object left, 
       Object right) throws ODataApplicationException {
 
-         // First check if the type of of both operands is numerical
+         // First check if the type of both operands is numerical
          if(left instanceof Integer && right instanceof Integer) {
            Integer valueLeft = (Integer) left;
            Integer valueRight = (Integer) right;

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b376959f/samples/tutorials/pom.xml
----------------------------------------------------------------------
diff --git a/samples/tutorials/pom.xml b/samples/tutorials/pom.xml
index c00028e..c4244dd 100644
--- a/samples/tutorials/pom.xml
+++ b/samples/tutorials/pom.xml
@@ -41,6 +41,7 @@
     <module>p4_navigation</module>
     <module>p5_queryoptions-tcs</module>
     <module>p6_queryoptions-es</module>
+    <module>p7_queryoptions-f</module>
   </modules>
 
   <build>

Reply via email to