public class Alternator extends Object
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
Constructor and Description |
---|
Alternator(boolean auto,
Object... list)
Creates a new Alternator for the specified list with the specified
automatic shifting preference.
|
Alternator(Object... list)
Creates a new Alternator for the specified list.
|
Modifier and Type | Method and Description |
---|---|
Object |
getCurrent()
Returns the current item without shifting the list index.
|
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.
|
String |
toString()
Returns a string representation of the current item or
null if the current item is null. |
public Alternator(Object... list)
list
- the elements to alternate overpublic Alternator(boolean auto, Object... list)
auto
- See setAuto(boolean auto)
.list
- The elements to alternate overpublic boolean isAuto()
toString()
.public void setAuto(boolean auto)
auto
- flag valuepublic void shift()
public Object getCurrent()
public Object getNext()
Copyright © 2002–2018 The Apache Software Foundation. All rights reserved.