/*
 * Copyright 2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.apache.velocity.tools.generic;

import java.util.List;

/**
 * Simple tool to provide easy in-template instantiation of
 * {@link Alternator}s from varying "list" types.
 *
 * <p><b>Example Use:</b>
 * <pre>
 * toolbox.xml...
 * &lt;tool&gt;
 *   &lt;key&gt;alternator&lt;/key&gt;
 *   &lt;scope&gt;application&lt;/scope&gt;
 *   &lt;class&gt;org.apache.velocity.tools.generic.AlternatorTool&lt;/class&gt;
 * &lt;/tool&gt;
 *
 * template...
 * #set( $color = $alternator.make('red', 'blue') )
 * ## use manual alternation for this one
 * #set( $style = $alternator.make(false, ['hip','fly','groovy']) )
 * #foreach( $i in [1..5] )
 *  $i 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
 * </pre></p>
 *
 * @since Velocity Tools 1.2
 * @version $Revision: 1.5 $ $Date: 2004/05/06 00:01:27 $
 */
public class AlternatorTool
{

    public AlternatorTool() {}

    /**
     * Make an automatic {@link Alternator} from a List.
     */
    public Alternator make(List list)
    {
        return make(false, list);
    }

    /**
     * Make an {@link Alternator} from a List.
     *
     * @return The new Alternator, or <code>null</code> if arguments
     * were illegal.
     */
    public Alternator make(boolean auto, List list)
    {
        if (list == null)
        {
            return null;
        }
        return new Alternator(auto, list);
    }

    /**
     * Make an automatic {@link Alternator} from an object array.
     */
    public Alternator make(Object[] array)
    {
        return make(false, array);
    }

    /**
     * Make an {@link Alternator} from an object array.
     *
     * @return The new Alternator, or <code>null</code> if arguments
     * were illegal.
     */
    public Alternator make(boolean auto, Object[] array)
    {
        if (array == null)
        {
            return null;
        }
        return new Alternator(auto, array);
    }

    /**
     * Make an automatic {@link Alternator} from a list containing the two
     * specified objects.
     *
     * @return The new Alternator, or <code>null</code> if arguments
     * were illegal.
     */
    public Alternator make(Object o1, Object o2)
    {
        return make(false, o1, o2);
    }

    /**
     * Make an {@link Alternator} from a list containing the two
     * specified objects.
     *
     * @param o1 The first of two objects for alternation between.
     * Must be non-<code>null</code>.
     * @param o2 The second of two objects for alternation between.
     * Must be non-<code>null</code>.
     * @return The new Alternator, or <code>null</code> if arguments
     * were illegal.
     */
    public Alternator make(boolean auto, Object o1, Object o2)
    {
        if (o1 == null || o2 == null)
        {
            return null;
        }
        return new Alternator(auto, new Object[] { o1, o2 });
    }

}

@@ -1492,43 +1492,15 @@
 sion
-: 1.5 
 $ $Date
-: 2004/05/06 00:01:27 
 $%0A *
@@ -1535,38 +1535,540 @@
 l%0A%7B%0A
-%0A    public AlternatorTool() %7B
+    // it's true by default in Alternator%0A    private boolean autoAlternateDefault = true;%0A%0A    public AlternatorTool() %7B%7D%0A%0A    /**%0A     * Returns true if the default for auto-alternating is true.%0A     * @since VelocityTools 1.3%0A     */%0A    public boolean getAutoAlternateDefault()%0A    %7B%0A        return autoAlternateDefault;%0A    %7D%0A%0A    /**%0A     * Sets the default for auto-alternating.%0A     * @since VelocityTools 1.3%0A     */%0A    public void setAutoAlternateDefault(boolean bool)%0A    %7B%0A        this.autoAlternateDefault = bool;%0A    
 %7D%0A%0A 
@@ -2203,21 +2203,36 @@
 rn make(
-false
+autoAlternateDefault
 , list);
@@ -2729,21 +2729,36 @@
 rn make(
-false
+autoAlternateDefault
 , array)
@@ -3410,21 +3410,36 @@
 rn make(
-false
+autoAlternateDefault
 , o1, o2

make default auto-alternation behavoir both configurable and matched to Alternator's default behavior