public class LoopTool.ManagedIterator extends Object implements Iterator
Iterator
and allows it to be prematurely stopped, skipped ahead, and
associated with a name for advanced nested loop control.
This also allows a arbitrary LoopTool.ActionCondition
s to be added
in order to have it automatically skip over or stop before
certain elements in the iterator.Constructor and Description |
---|
ManagedIterator(String name,
Iterator iterator,
LoopTool owner) |
Modifier and Type | Method and Description |
---|---|
LoopTool.ManagedIterator |
condition(LoopTool.ActionCondition condition)
Adds a new
LoopTool.ActionCondition for this instance to check
against the elements in the iterator being managed. |
LoopTool.ManagedIterator |
exclude(Object compare)
Directs this instance to completely exclude
any elements equal to the specified Object.
|
Object |
get(String name) |
int |
getCount() |
boolean |
getFirst() |
boolean |
getHasNext() |
int |
getIndex() |
boolean |
getLast() |
Map<String,Object> |
getLastSyncedValues() |
String |
getName() |
boolean |
hasNext() |
boolean |
isFirst() |
boolean |
isLast() |
boolean |
isSyncedWith(String name) |
Object |
next() |
void |
remove()
This operation is unsupported.
|
void |
stop()
Stops this iterator from doing any further iteration.
|
LoopTool.ManagedIterator |
stop(Object compare)
Directs this instance to stop iterating immediately prior to
any element equal to the specified Object.
|
LoopTool.ManagedIterator |
sync(Object iterable)
Adds another iterator to be kept in sync with the one
being managed by this instance.
|
LoopTool.ManagedIterator |
sync(Object iterable,
String name)
Adds another iterator to be kept in sync with the one
being managed by this instance.
|
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEachRemaining
public String getName()
public boolean isFirst()
next()
.public boolean isLast()
next()
is the last element available in the iterator being managed
which satisfies any/all LoopTool.ActionCondition
s set for this
instance. Otherwise, returns false.public boolean getFirst()
isFirst()
. Exists to allow $loop.this.first syntax.public boolean getLast()
isLast()
. Exists to allow $loop.this.last syntax.public boolean hasNext()
hasNext
in interface Iterator
LoopTool.ActionCondition
s set for this instance. Returns
false if there are no more valid elements available.public boolean getHasNext()
hasNext()
. Exists to allow $loop.this.hasNext syntax.public boolean isSyncedWith(String name)
name
- syn'ed iterator nametrue
if this ManagedIterator has a sync'ed
iterator with the specified name.public Object get(String name)
name
- iterator namenull
.public int getCount()
next()
so far.public int getIndex()
public Object next()
next
in interface Iterator
LoopTool.ActionCondition
s
(if any) in the iterator being managed. If there are none left, then
this will throw a NoSuchElementException
.public void remove()
public void stop()
public LoopTool.ManagedIterator exclude(Object compare)
compare
- value to excludeLoopTool.ManagedIterator
instancepublic LoopTool.ManagedIterator stop(Object compare)
compare
- value to stop atLoopTool.ManagedIterator
instancepublic LoopTool.ManagedIterator condition(LoopTool.ActionCondition condition)
LoopTool.ActionCondition
for this instance to check
against the elements in the iterator being managed.condition
- conditionLoopTool.ManagedIterator
instancepublic LoopTool.ManagedIterator sync(Object iterable)
Adds another iterator to be kept in sync with the one being managed by this instance. The values of the parallel iterator can be retrieved from the LoopTool under the name s"synced" (e.g. $loop.synced or $loop.get('synced')) and are automatically updated for each iteration by this instance.
NOTE: if you are sync'ing multiple iterators
with the same managed iterator, you must use
sync(Object,String)
or else your the later iterators
will simply replace the earlier ones under the default
'synced' key.
iterable
- Iterator to synchronize withLoopTool.ManagedIterator
instanceLoopTool.SyncedIterator
,
get(String)
public LoopTool.ManagedIterator sync(Object iterable, String name)
iterable
- iterator to synchronize withname
- loop nameLoopTool.ManagedIterator
instanceLoopTool.SyncedIterator
,
get(String)
Copyright © 2002–2018 The Apache Software Foundation. All rights reserved.