Debian Codegraph @

net/sf/saxon/expr/flwor/CountClausePull.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.XPathContext;
11 import net.sf.saxon.trans.XPathException;
12 import net.sf.saxon.value.Int64Value;
13
14 /**
15 * A tuple stream that implements a "count" clause in an XQuery 3.0 FLWOR expression
16 */
17 public class CountClausePull extends TuplePull {
18
19 TuplePull base;
20 int slot;
21 int count = 0;
22
23 public CountClausePull(TuplePull base, CountClause countClause) {
24 this.base = base;
25 this.slot = countClause.getRangeVariable().getLocalSlotNumber();
26 }
27
28 /**
29 * Move on to the next tuple. Before returning, this method must set all the variables corresponding
30 * to the "returned" tuple in the local stack frame associated with the context object
31 *
32 * @param context the dynamic evaluation context
33 * @return true if another tuple has been generated; false if the tuple stream is exhausted. If the
34 * method returns false, the values of the local variables corresponding to this tuple stream
35 * are undefined.
36 */
37 @Override
38 public boolean nextTuple(XPathContext context) throws XPathException {
39 if (!base.nextTuple(context)) {
40 count = 0;
41 context.setLocalVariable(slot, Int64Value.ZERO);
42 return false;
43 }
44 context.setLocalVariable(slot, new Int64Value(++count));
45 return true;
46 }
47 }
48
49 // Copyright (c) 2011 Saxonica Limited.