Skip to content
Browse files
[JXPATH-149] relational operations do not function properly when comp…
…aring a non-Iterator LHS to an Iterator RHS

git-svn-id: 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
mbenson committed Jun 8, 2011
1 parent a48b10d commit 820a69d81b3b5d33f4a2b2cd9f153450f7535452
Showing 2 changed files with 48 additions and 1 deletion.
@@ -85,7 +85,7 @@ private boolean compute(Object left, Object right) {
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)) {
@@ -129,6 +129,22 @@ private boolean containsMatch(Iterator it, Object value) {
return false;

* 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 =;
if (compute(value, element)) {
return true;
return false;

* Learn whether there is an intersection between two Iterators.
* @param lit left Iterator
@@ -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
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* 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);

0 comments on commit 820a69d

Please sign in to comment.