类 Alternator

java.lang.Object
org.apache.velocity.tools.generic.Alternator

public class Alternator extends Object
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
 

从以下版本开始:
Velocity Tools 1.2
版本:
$Id: Alternator.java 603419 2007-12-12 00:04:07Z nbubna $
  • 字段概要

    字段
    修饰符和类型
    字段
    说明
    private boolean
     
    private int
     
    private Object[]
     
  • 构造器概要

    构造器
    构造器
    说明
    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.
  • 方法概要

    修饰符和类型
    方法
    说明
    Returns the current item without shifting the list index.
    Returns the current item, then shifts the list index.
    boolean
     
    void
    setAuto(boolean auto)
    If set to true, the list index will shift automatically after a call to toString().
    void
    Manually shifts the list index.
    Returns a string representation of the current item or null if the current item is null.

    从类继承的方法 java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 字段详细资料

    • list

      private Object[] list
    • index

      private int index
    • auto

      private boolean auto
  • 构造器详细资料

    • Alternator

      public Alternator(Object... list)
      Creates a new Alternator for the specified list. Alternation defaults to automatic.
    • Alternator

      public Alternator(boolean auto, Object... list)
      Creates a new Alternator for the specified list with the specified automatic shifting preference.
      参数:
      auto - See setAuto(boolean auto).
      list - The elements to alternate over
  • 方法详细资料

    • isAuto

      public boolean isAuto()
      返回:
      Whether this Alternator shifts the list index automatically after a call to toString().
    • setAuto

      public void setAuto(boolean auto)
      If set to true, the list index will shift automatically after a call to toString().
    • shift

      public void shift()
      Manually shifts the list index. If it reaches the end of the list, it will start over again at zero.
    • getCurrent

      public Object getCurrent()
      Returns the current item without shifting the list index.
    • getNext

      public Object getNext()
      Returns the current item, then shifts the list index.
    • toString

      public String toString()
      Returns a string representation of the current item or null if the current item is null. If auto is true, this will shift after returning the current item.
      覆盖:
      toString 在类中 Object