|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.velocity.tools.generic.Alternator
public class Alternator
Utility class for easily alternating over values in a list.
Example usage:
java... String[] myColors = new String[]{"red", "blue"}; context.put("color", new Alternator(myColors)); String[] myStyles = new String[]{"hip", "fly", "groovy"}; // demonstrate manual alternation with this one context.put("style", new Alternator(false, myStyles)); template... #foreach( $foo in [1..5] ) $foo is $color and $style.next #end output... 1 is red and hip 2 is blue and fly 3 is red and groovy 4 is blue and hip 5 is red and fly
Field Summary | |
---|---|
private boolean |
auto
|
private int |
index
|
private java.lang.Object[] |
list
|
Constructor Summary | |
---|---|
Alternator(boolean auto,
java.util.List list)
Creates a new Alternator for the specified list with the specified automatic shifting preference. |
|
Alternator(boolean auto,
java.lang.Object[] list)
Creates a new Alternator for the specified list with the specified automatic shifting preference. |
|
Alternator(java.util.List list)
Creates a new Alternator for the specified list. |
|
Alternator(java.lang.Object[] list)
Creates a new Alternator for the specified list. |
Method Summary | |
---|---|
java.lang.Object |
getCurrent()
Returns the current item without shifting the list index. |
java.lang.Object |
getNext()
Returns the current item, then shifts the list index. |
boolean |
isAuto()
|
void |
setAuto(boolean auto)
If set to true, the list index will shift automatically after a call to toString(). |
void |
shift()
Manually shifts the list index. |
java.lang.String |
toString()
Returns a string representation of the current item or null if the current item is null. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private java.lang.Object[] list
private int index
private boolean auto
Constructor Detail |
---|
public Alternator(java.util.List list)
public Alternator(java.lang.Object[] list)
public Alternator(boolean auto, java.util.List list)
auto
- See setAuto(boolean auto)
.list
- The (non-null
) list of elements to
alternate.public Alternator(boolean auto, java.lang.Object[] list)
auto
- See setAuto(boolean auto)
.list
- The (non-null
) list of elements to
alternate.Method Detail |
---|
public boolean isAuto()
toString()
.public void setAuto(boolean auto)
public void shift()
public java.lang.Object getCurrent()
public java.lang.Object getNext()
public java.lang.String toString()
null
if the current item is null. If auto
is true, this will shift after returning the current
item.
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |