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).Modifier and Type | Method and Description |
---|---|
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
public void startFrom(Object subscript)
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.subscript
- subscript to start frompublic boolean hasNext()
true
if the iteration has more elements.
(In other words, returns true
if next()
would
return an element rather than throwing an exception.)public String next() throws NoSuchElementException
next
in interface Iterator
NoSuchElementException
- if the iteration has no more elementspublic void remove() throws IllegalStateException
remove
in interface Iterator
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).public String getSubscriptValue() throws IllegalStateException
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).public Object getValue() throws IllegalStateException
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).public boolean hasPrevious()
true
if the iteration has a previous element.
(In other words, returns true
if previous()
would
return an element rather than throwing an exception.)true
if the iteration has a previous elementpublic String previous() throws NoSuchElementException
NoSuchElementException
- if the iteration does not have a previous element© 2024 InterSystems Corporation, Cambridge, MA. All rights reserved. Privacy & Terms Guarantee Accessibility