|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.velocity.tools.generic.LoopTool.ManagedIterator
public static class LoopTool.ManagedIterator
Iterator implementation that wraps a standard 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.
Field Summary | |
---|---|
private java.util.List<LoopTool.ActionCondition> |
conditions
|
private int |
count
|
private java.lang.Boolean |
first
|
private java.util.Iterator |
iterator
|
private java.lang.String |
name
|
private java.lang.Object |
next
|
private LoopTool |
owner
|
private boolean |
stopped
|
private java.util.Map<java.lang.String,LoopTool.SyncedIterator> |
synced
|
Constructor Summary | |
---|---|
LoopTool.ManagedIterator(java.lang.String name,
java.util.Iterator iterator,
LoopTool owner)
|
Method Summary | |
---|---|
private boolean |
cacheNext(boolean popWhenDone)
|
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(java.lang.Object compare)
Directs this instance to completely exclude any elements equal to the specified Object. |
java.lang.Object |
get(java.lang.String name)
Returns the parallel value from the specified sync'ed iterator. |
int |
getCount()
Returns the number of elements returned by next() so far. |
boolean |
getFirst()
Returns the result of isFirst() . |
boolean |
getHasNext()
Returns the result of hasNext() . |
int |
getIndex()
Returns the 0-based index of the current item. |
boolean |
getLast()
Returns the result of isLast() . |
java.lang.String |
getName()
Returns the name of this instance. |
boolean |
hasNext()
Returns true if there are more elements in the iterator being managed by this instance which satisfy all the LoopTool.ActionCondition s set for this instance. |
private boolean |
hasNext(boolean popWhenDone)
|
boolean |
isFirst()
Returns true if either 0 or 1 elements have been returned by next() . |
boolean |
isLast()
Returns true if the last element returned by next()
is the last element available in the iterator being managed
which satisfies any/all LoopTool.ActionCondition s set for this
instance. |
boolean |
isSyncedWith(java.lang.String name)
Returns true if this ManagedIterator has a sync'ed
iterator with the specified name. |
java.lang.Object |
next()
Returns the next element that meets the set LoopTool.ActionCondition s
(if any) in the iterator being managed. |
void |
remove()
This operation is unsupported. |
private void |
shiftSynced()
|
void |
stop()
Stops this iterator from doing any further iteration. |
LoopTool.ManagedIterator |
stop(java.lang.Object compare)
Directs this instance to stop iterating immediately prior to any element equal to the specified Object. |
LoopTool.ManagedIterator |
sync(java.lang.Object iterable)
Adds another iterator to be kept in sync with the one being managed by this instance. |
LoopTool.ManagedIterator |
sync(java.lang.Object iterable,
java.lang.String name)
Adds another iterator to be kept in sync with the one being managed by this instance. |
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private java.lang.String name
private java.util.Iterator iterator
private LoopTool owner
private boolean stopped
private java.lang.Boolean first
private int count
private java.lang.Object next
private java.util.List<LoopTool.ActionCondition> conditions
private java.util.Map<java.lang.String,LoopTool.SyncedIterator> synced
Constructor Detail |
---|
public LoopTool.ManagedIterator(java.lang.String name, java.util.Iterator iterator, LoopTool owner)
Method Detail |
---|
public java.lang.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()
LoopTool.ActionCondition
s set for this instance. Returns
false if there are no more valid elements available.
hasNext
in interface java.util.Iterator
public boolean getHasNext()
hasNext()
. Exists to allow $loop.this.hasNext syntax.
private boolean hasNext(boolean popWhenDone)
private boolean cacheNext(boolean popWhenDone)
private void shiftSynced()
public boolean isSyncedWith(java.lang.String name)
true
if this ManagedIterator has a sync'ed
iterator with the specified name.
public java.lang.Object get(java.lang.String name)
null
.
public int getCount()
next()
so far.
public int getIndex()
public java.lang.Object next()
LoopTool.ActionCondition
s
(if any) in the iterator being managed. If there are none left, then
this will throw a NoSuchElementException
.
next
in interface java.util.Iterator
public void remove()
remove
in interface java.util.Iterator
public void stop()
public LoopTool.ManagedIterator exclude(java.lang.Object compare)
LoopTool.ManagedIterator
instancepublic LoopTool.ManagedIterator stop(java.lang.Object compare)
LoopTool.ManagedIterator
instancepublic LoopTool.ManagedIterator condition(LoopTool.ActionCondition condition)
LoopTool.ActionCondition
for this instance to check
against the elements in the iterator being managed.
LoopTool.ManagedIterator
instancepublic LoopTool.ManagedIterator sync(java.lang.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.synched 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.
LoopTool.ManagedIterator
instanceLoopTool.SyncedIterator
,
get(String)
public LoopTool.ManagedIterator sync(java.lang.Object iterable, java.lang.String name)
LoopTool.ManagedIterator
instanceLoopTool.SyncedIterator
,
get(String)
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |