com.intersystems.jdbc

## Class IRISIterator

- java.lang.Object
- - com.intersystems.jdbc.IRISIterator

All Implemented Interfaces:
  Iterator

    public class IRISIterator
    extends Object
    implements Iterator

`IRISIterator` allows iterating over the global in the $ORDER sense. In addition to standard methods hasNext and next, this class also provides means of iterating backwards (hasPrevious and previous), as well as retrieving the subscript as well as the node values. The global reference (globalName + subscripts) with which this class is instantiated specifies the root global node. An instance of this class will iterate over the immediate children of the root node. For example, for the following global: ^gbl(1)="a" ^gbl(1,11)="b" ^gbl(1,12)="c" ^gbl(2)="d" Calling IRIS.getIRISIterator("^gbl") will return an iterator that traverses the immediate children of ^gbl, that is, ^gbl(1) and ^gbl(2). Calling IRIS.getIRISIterator("^gbl",1) will return an iterator that traverses the immediate children of ^gbl(1), that is, ^gbl(1,11) and ^gbl(1,12).

### Method Summary

All Methods Instance Methods Concrete Methods
`String` `getSubscriptValue()` Returns the value of the current subscript.
`Object` `getValue()` Returns the current value.
`boolean` `hasNext()` Returns `true` if the iteration has more elements.
`boolean` `hasPrevious()` Returns `true` if the iteration has a previous element.
`String` `next()` Returns the next element in the iteration.
`String` `previous()` Returns the previous element in the iteration.
`void` `remove()` Removes from the underlying collection the last element returned by this iterator.
`void` `startFrom(Object subscript)` Sets the iterator's starting position to the specified subscript.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Methods inherited from interface java.util.Iterator

`forEachRemaining`

### Method Detail

#### startFrom

    public void startFrom(Object subscript)

Sets the iterator's starting position to the specified subscript. After calling this method, use `next()` or `previous()` to advance the iterator to the next defined sub-node in alphabetic collating sequence. Note that calling `getSubscriptValue()` or `getValue()` before the iterator is advanced at least one position will result in an IllegalStateException, since the iterator is not positioned at a defined sub-node. For example, for the following global and iterator: ^gbl("a")=11 ^gbl("b")=22 ^gbl("e")=55 IRISIterator itr = iris.getIRISIterator("^gbl"); The starting position may be a valid sub-node, in which case the next sub-node will be the next valid one. itr.startFrom("a"); while(itr.hasNext()) { itr.next(); System.out.println("subscript="+itr.getSubscriptValue()+", value="+itr.getValue()); } // prints: subscript=b, value=11; subscript=e, value=55 The starting position may also be an invalid sub-node, in which case the next sub-node will be the first valid one in alphabetic collating sequence after the given subscript. itr.startFrom("c"); while(itr.hasNext()) { itr.next(); System.out.println("subscript="+itr.getSubscriptValue()+", value="+itr.getValue()); } // prints: subscript=e, value=55 Calling this method with null as the argument is the same as using the default starting position, which is just before the first sub-node.

Parameters:
  `subscript` - subscript to start from

#### hasNext

    public boolean hasNext()

Returns `true` if the iteration has more elements. (In other words, returns `true` if `next()` would return an element rather than throwing an exception.)

Specified by:
  `hasNext` in interface `Iterator`
Returns:
  `true` if the iteration has more elements

#### next

    public String next()
                throws NoSuchElementException

Returns the next element in the iteration.

Specified by:
  `next` in interface `Iterator`
Returns:
  the next element in the iteration
Throws:
  `NoSuchElementException` - if the iteration has no more elements

#### remove

    public void remove()
                throws IllegalStateException

Removes from the underlying collection the last element returned by this iterator. This method can be called only once per call to next() or previous().

Specified by:
  `remove` in interface `Iterator`
Throws:
  `IllegalStateException` - if remove() has been called on the current node with this iterator, or there is no last element returned by this iterator (i.e. no successful next() or previous() calls).

#### getSubscriptValue

    public String getSubscriptValue()
                             throws IllegalStateException

Returns the value of the current subscript.

Returns:
  the current subscript value.
Throws:
  `IllegalStateException` - if remove() has been called on the current node with this iterator, or there is no last element returned by this iterator (i.e. no successful next() or previous() calls).

#### getValue

    public Object getValue()
                    throws IllegalStateException

Returns the current value.

Returns:
  the current value.
Throws:
  `IllegalStateException` - if remove() has been called on the current node with this iterator, or there is no last element returned by this iterator (i.e. no successful next() or previous() calls).

#### hasPrevious

    public boolean hasPrevious()

Returns `true` if the iteration has a previous element. (In other words, returns `true` if `previous()` would return an element rather than throwing an exception.)

Returns:
  `true` if the iteration has a previous element

#### previous

    public String previous()
                    throws NoSuchElementException

Returns the previous element in the iteration.

Returns:
  the previous element in the iteration
Throws:
  `NoSuchElementException` - if the iteration does not have a previous element