commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r1133485 - in /commons/proper/jxpath/trunk/src: java/org/apache/commons/jxpath/ri/compiler/CoreOperationRelationalExpression.java test/org/apache/commons/jxpath/ri/compiler/JXPath149Test.java
Date Wed, 08 Jun 2011 17:58:56 GMT
Author: mbenson
Date: Wed Jun  8 17:58:55 2011
New Revision: 1133485

URL: http://svn.apache.org/viewvc?rev=1133485&view=rev
Log:
[JXPATH-149] relational operations do not function properly when comparing a non-Iterator
LHS to an Iterator RHS

Added:
    commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/JXPath149Test.java
  (with props)
Modified:
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationRelationalExpression.java

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationRelationalExpression.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationRelationalExpression.java?rev=1133485&r1=1133484&r2=1133485&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationRelationalExpression.java
(original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/compiler/CoreOperationRelationalExpression.java
Wed Jun  8 17:58:55 2011
@@ -85,7 +85,7 @@ public abstract class CoreOperationRelat
             return containsMatch((Iterator) left, right);
         }
         if (right instanceof Iterator) {
-            return containsMatch((Iterator) right, left);
+            return containsMatch(left, (Iterator) right);
         }
         double ld = InfoSetUtil.doubleValue(left);
         if (Double.isNaN(ld)) {
@@ -130,6 +130,22 @@ public abstract class CoreOperationRelat
     }
 
     /**
+     * Learn whether any element returned from an Iterator matches a given value.
+     * @param it Iterator
+     * @param value to look for
+     * @return whether a match was found
+     */
+    private boolean containsMatch(Object value, Iterator it) {
+        while (it.hasNext()) {
+            Object element = it.next();
+            if (compute(value, element)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
      * Learn whether there is an intersection between two Iterators.
      * @param lit left Iterator
      * @param rit right Iterator

Added: commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/JXPath149Test.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/JXPath149Test.java?rev=1133485&view=auto
==============================================================================
--- commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/JXPath149Test.java
(added)
+++ commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/JXPath149Test.java
Wed Jun  8 17:58:55 2011
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.jxpath.ri.compiler;
+
+import org.apache.commons.jxpath.JXPathContext;
+import org.apache.commons.jxpath.JXPathTestCase;
+
+public class JXPath149Test extends JXPathTestCase {
+
+    public void testComplexOperationWithVariables() {
+        JXPathContext context = JXPathContext.newContext(null);
+        context.getVariables().declareVariable("a", Integer.valueOf(0));
+        context.getVariables().declareVariable("b", Integer.valueOf(0));
+        context.getVariables().declareVariable("c", Integer.valueOf(1));
+        assertXPathValue(context, "$a + $b <= $c", Boolean.TRUE);
+    }
+}

Propchange: commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/compiler/JXPath149Test.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message