cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r1510017 - in /cayenne/main/trunk/framework/cayenne-core-unpublished/src: main/java/org/apache/cayenne/exp/parser/Evaluator.java test/java/org/apache/cayenne/exp/parser/EvaluatorTest.java
Date Sat, 03 Aug 2013 15:50:01 GMT
Author: aadamchik
Date: Sat Aug  3 15:50:01 2013
New Revision: 1510017

URL: http://svn.apache.org/r1510017
Log:
CAY-1860  In-memory matching of DataObjects against ObjectId or int

optimizing null handling

Modified:
    cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/exp/parser/Evaluator.java
    cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/exp/parser/EvaluatorTest.java

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/exp/parser/Evaluator.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/exp/parser/Evaluator.java?rev=1510017&r1=1510016&r2=1510017&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/exp/parser/Evaluator.java
(original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/main/java/org/apache/cayenne/exp/parser/Evaluator.java
Sat Aug  3 15:50:01 2013
@@ -43,20 +43,21 @@ abstract class Evaluator {
     private static final Evaluator BIG_DECIMAL_EVALUATOR;
     private static final Evaluator COMPAREABLE_EVALUATOR;
 
-    static class NullEvaluator extends Evaluator {
-        Evaluator delegate;
+    /**
+     * A decorator of an evaluator that presumes non-null 'lhs' argument and
+     * allows for null 'rhs'.
+     */
+    static class NonNullLhsEvaluator extends Evaluator {
+        final Evaluator delegate;
 
-        NullEvaluator(Evaluator delegate) {
+        NonNullLhsEvaluator(Evaluator delegate) {
             this.delegate = delegate;
         }
 
         @Override
         int compare(Object lhs, Object rhs) {
-            if (lhs == null && rhs == null) {
-                return 0;
-            } else if (lhs == null) {
-                return -1;
-            } else if (rhs == null) {
+
+            if (rhs == null) {
                 return 1;
             } else {
                 return delegate.compare(lhs, rhs);
@@ -65,11 +66,7 @@ abstract class Evaluator {
 
         @Override
         boolean eq(Object lhs, Object rhs) {
-            if (lhs == null) {
-                return rhs == null;
-            }
-
-            return (rhs != null) ? delegate.eq(lhs, rhs) : false;
+            return rhs == null ? false : delegate.eq(lhs, rhs);
         }
     }
 
@@ -88,7 +85,7 @@ abstract class Evaluator {
             }
         };
 
-        DEFAULT_EVALUATOR = new NullEvaluator(new Evaluator() {
+        DEFAULT_EVALUATOR = new NonNullLhsEvaluator(new Evaluator() {
             @Override
             boolean eq(Object lhs, Object rhs) {
                 return lhs.equals(rhs);
@@ -100,7 +97,7 @@ abstract class Evaluator {
             }
         });
 
-        PERSISTENT_EVALUATOR = new NullEvaluator(new Evaluator() {
+        PERSISTENT_EVALUATOR = new NonNullLhsEvaluator(new Evaluator() {
 
             @Override
             int compare(Object lhs, Object rhs) {
@@ -145,7 +142,7 @@ abstract class Evaluator {
             }
         });
 
-        BIG_DECIMAL_EVALUATOR = new NullEvaluator(new Evaluator() {
+        BIG_DECIMAL_EVALUATOR = new NonNullLhsEvaluator(new Evaluator() {
 
             @Override
             int compare(Object lhs, Object rhs) {
@@ -162,7 +159,7 @@ abstract class Evaluator {
             }
         });
 
-        COMPAREABLE_EVALUATOR = new NullEvaluator(new Evaluator() {
+        COMPAREABLE_EVALUATOR = new NonNullLhsEvaluator(new Evaluator() {
 
             @SuppressWarnings({ "unchecked", "rawtypes" })
             @Override

Modified: cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/exp/parser/EvaluatorTest.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/exp/parser/EvaluatorTest.java?rev=1510017&r1=1510016&r2=1510017&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/exp/parser/EvaluatorTest.java
(original)
+++ cayenne/main/trunk/framework/cayenne-core-unpublished/src/test/java/org/apache/cayenne/exp/parser/EvaluatorTest.java
Sat Aug  3 15:50:01 2013
@@ -47,6 +47,16 @@ public class EvaluatorTest extends TestC
         assertFalse(e.eq(o, null));
     }
 
+    public void testEvaluator_Number() {
+
+        Evaluator e = Evaluator.evaluator(1);
+        assertNotNull(e);
+        assertTrue(e.eq(1, 1));
+        assertFalse(e.eq(1, null));
+        assertFalse(e.eq(1, 5));
+        assertFalse(e.eq(1, 1.1));
+    }
+
     public void testEvaluator_BigDecimal() {
         Object lhs = new BigDecimal("1.10");
         Evaluator e = Evaluator.evaluator(lhs);



Mime
View raw message