You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by dl...@apache.org on 2004/05/05 22:51:55 UTC

cvs commit: jakarta-velocity-tools/src/java/org/apache/velocity/tools/generic Alternator.java

dlr         2004/05/05 13:51:55

  Modified:    src/java/org/apache/velocity/tools/generic Alternator.java
  Log:
  * src/java/org/apache/velocity/tools/generic/Alternator.java
    Added @since tag.
  
    list: Changed type from java.util.List to Object[] for faster access
    to static data.
  
    Alternator(Object[]): New ctor overload.
  
    Alternator(List): Changed impl. to delegate to other ctor.
  
    Alternator(boolean, Object[]): New, primary ctor which initializes
    "auto" and "list" instance fields.
  
    Alternator(boolean, List): Improve JavaDoc, delegated to other ctor.
  
    isAuto(): Improved JavaDoc.
  
    shift(), getCurrent(), toString(): Adjusted for change of "list"
    data type.
  
    getNext(): Tweaked JavaDoc.
  
  Revision  Changes    Path
  1.2       +40 -12    jakarta-velocity-tools/src/java/org/apache/velocity/tools/generic/Alternator.java
  
  Index: Alternator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity-tools/src/java/org/apache/velocity/tools/generic/Alternator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -u -r1.1 -r1.2
  --- Alternator.java	4 May 2004 03:32:22 -0000	1.1
  +++ Alternator.java	5 May 2004 20:51:55 -0000	1.2
  @@ -48,35 +48,63 @@
    *      5 is red and fly
    * </pre></p>
    *
  + * @since Velocity Tools 1.2
    * @version $Revision$ $Date$
    */
   public class Alternator
   {
  -    private List list;
  +    private Object[] list;
       private int index = 0;
       private boolean auto = false;
   
       /**
  -     * Creates a new Alternator for the specified list.
  +     * Creates a new Alternator for the specified list.  Alternation
  +     * is set to explicit (e.g. it's not automatic).
        */
  -    public Alternator(List list)
  +    public Alternator(Object[] list)
       {
  -        this.list = list;
  +        this(false, list);
       }
   
       /**
        * Creates a new Alternator for the specified list with the specified
  -     * automatic shifting preference.  See {@link #setAuto(boolean auto)}.
  +     * automatic shifting preference.
  +     *
  +     * @param auto See {@link #setAuto(boolean auto)}.
  +     * @param list The (non-<code>null</code>) list of elements to
  +     * alternate.
        */
       public Alternator(boolean auto, List list)
       {
  +        this(auto, list.toArray(new Object[list.size()]));
  +    }
  +
  +    /**
  +     * Creates a new Alternator for the specified list.  Alternation
  +     * is set to explicit (e.g. it's not automatic).
  +     */
  +    public Alternator(List list)
  +    {
  +        this(false, list);
  +    }
  +
  +    /**
  +     * Creates a new Alternator for the specified list with the specified
  +     * automatic shifting preference.
  +     *
  +     * @param auto See {@link #setAuto(boolean auto)}.
  +     * @param list The (non-<code>null</code>) list of elements to
  +     * alternate.
  +     */
  +    public Alternator(boolean auto, Object[] list)
  +    {
           this.auto = auto;
           this.list = list;
       }
   
       /**
  -     * Returns true if this Alternator shifts the list index automatically
  -     * after a call to toString().
  +     * @return Whether this Alternator shifts the list index
  +     * automatically after a call to {@link #toString()}.
        */
       public boolean isAuto()
       {
  @@ -98,7 +126,7 @@
        */
       public void shift()
       {
  -        index = (index + 1) % list.size();
  +        index = (index + 1) % list.length;
       }
   
       /**
  @@ -106,11 +134,11 @@
        */
       public Object getCurrent()
       {
  -        return list.get(index);
  +        return list[index];
       }
   
       /**
  -     * Returns the current item before shifting the list index.
  +     * Returns the current item, then shifts the list index.
        */
       public Object getNext()
       {
  @@ -127,7 +155,7 @@
        */
       public String toString()
       {
  -        Object o = list.get(index);
  +        Object o = list[index];
           if (auto)
           {
               shift();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org