commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r570233 - in /commons/proper/jxpath/trunk/src: java/org/apache/commons/jxpath/ri/axes/UnionContext.java test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
Date Mon, 27 Aug 2007 19:52:57 GMT
Author: mbenson
Date: Mon Aug 27 12:52:56 2007
New Revision: 570233

URL: http://svn.apache.org/viewvc?rev=570233&view=rev
Log:
[JXPATH-100] sort union when pulling first matching node

Modified:
    commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/axes/UnionContext.java
    commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java

Modified: commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/axes/UnionContext.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/axes/UnionContext.java?rev=570233&r1=570232&r2=570233&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/axes/UnionContext.java
(original)
+++ commons/proper/jxpath/trunk/src/java/org/apache/commons/jxpath/ri/axes/UnionContext.java
Mon Aug 27 12:52:56 2007
@@ -16,9 +16,11 @@
  */
 package org.apache.commons.jxpath.ri.axes;
 
-import java.util.HashSet;
+import java.util.ArrayList;
+import java.util.Iterator;
 
 import org.apache.commons.jxpath.BasicNodeSet;
+import org.apache.commons.jxpath.Pointer;
 import org.apache.commons.jxpath.ri.EvalContext;
 import org.apache.commons.jxpath.ri.model.NodePointer;
 
@@ -46,18 +48,22 @@
         if (!prepared) {
             prepared = true;
             BasicNodeSet nodeSet = (BasicNodeSet) getNodeSet();
-            HashSet set = new HashSet();
+            ArrayList pointers = new ArrayList();
             for (int i = 0; i < contexts.length; i++) {
                 EvalContext ctx = (EvalContext) contexts[i];
                 while (ctx.nextSet()) {
                     while (ctx.nextNode()) {
                         NodePointer ptr = ctx.getCurrentNodePointer();
-                        if (!set.contains(ptr)) {
-                            nodeSet.add(ptr);
-                            set.add(ptr);
+                        if (!pointers.contains(ptr)) {
+                            pointers.add(ptr);
                         }
                     }
                 }
+            }
+            sortPointers(pointers);
+
+            for (Iterator it = pointers.iterator(); it.hasNext();) {
+                nodeSet.add((Pointer) it.next());
             }
         }
         return super.setPosition(position);

Modified: commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java?rev=570233&r1=570232&r2=570233&view=diff
==============================================================================
--- commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
(original)
+++ commons/proper/jxpath/trunk/src/test/org/apache/commons/jxpath/ri/model/XMLModelTestCase.java
Mon Aug 27 12:52:56 2007
@@ -828,4 +828,9 @@
                 "Box of oranges",
                 "/vendor[1]/product[1]/goods:name[1]");
     }
+
+    public void testUnion() {
+        assertXPathValue(context, "/vendor[1]/contact[1] | /vendor[1]/contact[4]", "John");
+        assertXPathValue(context, "/vendor[1]/contact[4] | /vendor[1]/contact[1]", "John");
+    }
 }



Mime
View raw message