Debian Codegraph @

net/sf/saxon/expr/flwor/WhereClausePull.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.expr.flwor;
9
10 import net.sf.saxon.expr.Expression;
11 import net.sf.saxon.expr.XPathContext;
12 import net.sf.saxon.trans.XPathException;
13
14 /**
15 * This class represents the tuple stream delivered as the output of a where clause in a
16 * FLWOR expression: that is, it returns all the tuples in its input stream that satisfy
17 * a specified predicate. It does not change the values of any variables in the tuple stream.
18 */
19 public class WhereClausePull extends TuplePull {
20
21 TuplePull base;
22 Expression predicate;
23
24 public WhereClausePull(TuplePull base, Expression predicate) {
25 this.base = base;
26 this.predicate = predicate;
27 }
28
29 /**
30 * Move on to the next tuple. Before returning, this method must set all the variables corresponding
31 * to the "returned" tuple in the local stack frame associated with the context object
32 *
33 * @param context the dynamic evaluation context
34 * @return true if another tuple has been generated; false if the tuple stream is exhausted. If the
35 * method returns false, the values of the local variables corresponding to this tuple stream
36 * are undefined.
37 */
38 @Override
39 public boolean nextTuple(XPathContext context) throws XPathException {
40 while (base.nextTuple(context)) {
41 if (predicate.effectiveBooleanValue(context)) {
42 return true;
43 }
44 }
45 return false;
46 }
47
48 /**
49 * Close the tuple stream, indicating that although not all tuples have been read,
50 * no further tuples are required and resources can be released
51 */
52 @Override
53 public void close() {
54 base.close();
55 }
56 }
57