| 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.om; |
| 9 | |
| 10 | import net.sf.saxon.trans.XPathException; |
| 11 | |
| 12 | /** |
| 13 | * An iterator that maintains the values of position() and current(), |
| 14 | * typically implemented as a wrapper over an iterator which does not maintain these values itself. |
| 15 | */ |
| 16 | public interface FocusIterator<T extends Item<?>> extends SequenceIterator<T> { |
| 17 | |
| 18 | /** |
| 19 | * Get the current value in the sequence (the one returned by the |
| 20 | * most recent call on next()). This will be null before the first |
| 21 | * call of next(). This method does not change the state of the iterator. |
| 22 | * |
| 23 | * @return the current item, the one most recently returned by a call on |
| 24 | * next(). Returns null if next() has not been called, or if the end |
| 25 | * of the sequence has been reached. |
| 26 | * @since 8.4 |
| 27 | */ |
| 28 | T current(); |
| 29 | |
| 30 | /** |
| 31 | * Get the current position. This will usually be zero before the first call |
| 32 | * on next(), otherwise it will be the number of times that next() has |
| 33 | * been called. Once next() has returned null, the preferred action is |
| 34 | * for subsequent calls on position() to return -1, but not all existing |
| 35 | * implementations follow this practice. (In particular, the EmptyIterator |
| 36 | * is stateless, and always returns 0 as the value of position(), whether |
| 37 | * or not next() has been called.) |
| 38 | * <p>This method does not change the state of the iterator.</p> |
| 39 | * |
| 40 | * @return the current position, the position of the item returned by the |
| 41 | * most recent call of next(). This is 1 after next() has been successfully |
| 42 | * called once, 2 after it has been called twice, and so on. If next() has |
| 43 | * never been called, the method returns zero. If the end of the sequence |
| 44 | * has been reached, the value returned will always be <= 0; the preferred |
| 45 | * value is -1. |
| 46 | * @since 8.4 |
| 47 | */ |
| 48 | int position(); |
| 49 | |
| 50 | /** |
| 51 | * Get the position of the last item in the sequence |
| 52 | * @return the position of the last item |
| 53 | * @throws XPathException if a failure occurs reading the sequence |
| 54 | */ |
| 55 | |
| 56 | int getLength() throws XPathException; |
| 57 | |
| 58 | } |