Debian Codegraph @

net/sf/saxon/expr/flwor/CountClausePush.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 in push mode that implements a "count" clause in an XQuery 3.0 FLWOR expression
16 */
17 public class CountClausePush extends TuplePush {
18
19 TuplePush destination;
20 int slot;
21 int count = 0;
22
23 public CountClausePush(TuplePush destination, CountClause countClause) {
24 this.destination = destination;
25 this.slot = countClause.getRangeVariable().getLocalSlotNumber();
26 }
27
28 /*
29 * Notify the next tuple.
30 */
31 @Override
32 public void processTuple(XPathContext context) throws XPathException {
33 context.setLocalVariable(slot, new Int64Value(++count));
34 destination.processTuple(context);
35 }
36
37 /**
38 * Close the tuple stream, indicating that no more tuples will be supplied
39 */
40 @Override
41 public void close() throws XPathException {
42 destination.close();
43 }
44 }
45
46 // Copyright (c) 2011 Saxonica Limited.