Debian Codegraph @

net/sf/saxon/z/IntStepIterator.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.z;
9
10 /**
11 * An iterator over a sequence of integers with regular steps, e.g. 2, 4, 6, 8...
12 */
13
14 public class IntStepIterator implements IntIterator {
15
16 private int current;
17 private int step;
18 private int limit;
19
20 /**
21 * Create an iterator over a sequence with regular steps
22 * @param start the first value to be returned
23 * @param step the difference between successive values (must be non-zero)
24 * @param limit if step>0, the iteration will not deliver any values greater than this limit;
25 * if step<0 the iteration will not deliver any values lower than this limit
26 */
27
28 public IntStepIterator(int start, int step, int limit) {
29 this.current = start;
30 this.step = step;
31 this.limit = limit;
32 }
33
34 public boolean hasNext() {
35 return step>0 ? current <= limit : current >= limit;
36 }
37
38 public int next() {
39 int n = current;
40 current += step;
41 return n;
42 }
43
44 }