|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object
|
+--org.apache.velocity.tools.Camwood
|
+--org.apache.velocity.tools.FisherMill
A convenience tool for use in #foreach loops. It wraps a list to let the designer specify a condition to terminate the loop, and reuse the same list in different loops.
Example of use:
Java
----
context.put("mill", new FisherMill());
VTL
---
#set ($list = [1, 2, 3, 5, 8, 13])
#set ($numbers = $mill.wrap($list))
#foreach ($item in $numbers)
#if ($item < 8) $numbers.more()#end
#end
$numbers.more()
Output
------
1 2 3 5
8
Warning: It is not recommended to call hasNext() directly as this method is used to control the #foreach. Use hasMore() instead.
| Field Summary | |
protected boolean |
cachedNext
True if next contains the value of the next element in the list. |
protected java.lang.Object |
next
The next element in the list, if it was cached. |
| Constructor Summary | |
FisherMill()
Create a FisherMill instance to use as tool. |
|
FisherMill(java.lang.Object list)
Create a FisherMill instance to use in #foreach. |
|
| Method Summary | |
void |
cont()
Proceeds to the next element in the list. |
boolean |
hasNext()
Returns true if there are more elements in the list and more() was called. |
java.lang.Object |
more()
Asks for the next element in the list. |
java.lang.Object |
next()
Gets the next element in the list. |
void |
remove()
Removes the current element from the list. |
void |
reset()
Resets the wrapper so that it starts over at the beginning of the list. |
Camwood |
wrap(java.lang.Object list)
Wraps a list with the tool. |
| Methods inherited from class org.apache.velocity.tools.Camwood |
hasMore, isTool, stop, toString |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
protected boolean cachedNext
protected java.lang.Object next
| Constructor Detail |
public FisherMill()
public FisherMill(java.lang.Object list)
list - The list to wrap.| Method Detail |
public Camwood wrap(java.lang.Object list)
Camwoodwrap in class Camwoodorg.apache.velocity.tools.Camwoodlist - The list to wrap.public void reset()
CamwoodResets the wrapper so that it starts over at the beginning of the list.
Note to programmers: This method has no effect if the wrapped object is an enumeration or an iterator.
reset in class Camwoodpublic java.lang.Object next()
Gets the next element in the list. This method is called by #foreach to define $item in:
#foreach( $item in $list )
This method is not intended for template designers, but they can use it if they want to read the value of the next item without doing more().
next in class CamwoodNoSuchElementException - if there are no more elements in the list.more(),
Camwood.hasMore()public boolean hasNext()
tool.hasNext()? tool.hasNext(): false;
hasNext in class CamwoodCamwood.hasMore()
public void remove()
throws java.lang.UnsupportedOperationException
remove in class Camwoodjava.lang.UnsupportedOperationException - if the wrapped list iterator doesn't support this
operation.public java.lang.Object more()
Asks for the next element in the list. This method is to be used by the template designer in #foreach loops.
If this method is called in the body of #foreach, the loop continues as
long as there are elements in the list.
If this method is not called the loop terminates after the current iteration.
Camwood.hasMore()public void cont()
cont in class Camwoodmore()
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||