incubator-vxquery-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ti...@apache.org
Subject svn commit: r996203 - in /incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery: functions/builtin-operators.xml runtime/functions/OpExceptIterator.java
Date Sat, 11 Sep 2010 19:47:16 GMT
Author: tillw
Date: Sat Sep 11 19:47:15 2010
New Revision: 996203

URL: http://svn.apache.org/viewvc?rev=996203&view=rev
Log:
added op:except

Added:
    incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/runtime/functions/OpExceptIterator.java
Modified:
    incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/functions/builtin-operators.xml

Modified: incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/functions/builtin-operators.xml
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/functions/builtin-operators.xml?rev=996203&r1=996202&r2=996203&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/functions/builtin-operators.xml
(original)
+++ incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/functions/builtin-operators.xml
Sat Sep 11 19:47:15 2010
@@ -196,6 +196,8 @@
         <param name="parameter1" type="node()*"/>
         <param name="parameter2" type="node()*"/>
         <return type="node()*"/>
+        <!-- implementation assumes input in document order -->
+        <runtime class="org.apache.vxquery.runtime.functions.OpExceptIterator"/>
     </operator>
 
     <!-- op:gDay-equal($arg1  as xs:gDay, $arg2 as xs:gDay)  as xs:boolean -->

Added: incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/runtime/functions/OpExceptIterator.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/runtime/functions/OpExceptIterator.java?rev=996203&view=auto
==============================================================================
--- incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/runtime/functions/OpExceptIterator.java
(added)
+++ incubator/vxquery/trunk/vxquery/src/main/java/org/apache/vxquery/runtime/functions/OpExceptIterator.java
Sat Sep 11 19:47:15 2010
@@ -0,0 +1,72 @@
+/*
+* 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.vxquery.runtime.functions;
+
+import org.apache.vxquery.context.StaticContext;
+import org.apache.vxquery.datamodel.XDMNode;
+import org.apache.vxquery.exceptions.SystemException;
+import org.apache.vxquery.functions.Function;
+import org.apache.vxquery.runtime.CallStackFrame;
+import org.apache.vxquery.runtime.LocalRegisterAccessor;
+import org.apache.vxquery.runtime.RegisterAllocator;
+import org.apache.vxquery.runtime.base.AbstractLazilyEvaluatedFunctionIterator;
+import org.apache.vxquery.runtime.base.RuntimeIterator;
+
+public class OpExceptIterator extends AbstractLazilyEvaluatedFunctionIterator {
+    private final LocalRegisterAccessor<XDMNode> nextException;
+
+    public OpExceptIterator(RegisterAllocator rAllocator, Function fn, RuntimeIterator[]
arguments, StaticContext ctx) {
+        super(rAllocator, fn, arguments, ctx);
+        nextException = new LocalRegisterAccessor<XDMNode>(rAllocator.allocate(1));
+    }
+
+    @Override
+    public void close(CallStackFrame frame) {
+        arguments[1].close(frame);
+        arguments[0].close(frame);
+    }
+
+    @Override
+    public Object next(CallStackFrame frame) throws SystemException {
+        XDMNode left = (XDMNode) arguments[0].next(frame);
+        XDMNode right = nextException.get(frame);
+        while (left != null) {
+            if (right == null) {
+                right = (XDMNode) arguments[1].next(frame);
+            }
+            if (right == null || left.compareDocumentOrder(right) < 0) {
+                nextException.set(frame, right);
+                return left;
+            }
+            while (right != null && left.compareDocumentOrder(right) > 0) {
+                right = (XDMNode) arguments[1].next(frame);
+            }
+            if (right == null || !left.isSameNode(right)) {
+                nextException.set(frame, right);
+                return left;
+            }
+            left = (XDMNode) arguments[0].next(frame);
+        }
+        return null;
+    }
+
+    @Override
+    public void open(CallStackFrame frame) {
+        arguments[0].open(frame);
+        arguments[1].open(frame);
+    }
+}



Mime
View raw message