/*
 * @(#)TestIterable.java
 *
 * Summary: example use of Iterable.
 *
 * Copyright: (c) 2009-2010 Roedy Green, Canadian Mind Products, http://mindprod.com
 *
 * Licence: This software may be copied and used freely for any purpose but military.
 *          http://mindprod.com/contact/nonmil.html
 *
 * Requires: JDK 1.6+
 *
 * Created with: IntelliJ IDEA IDE.
 *
 * Version History:
 *  1.0 2009-01-01 - initial version
 */
package com.mindprod.example;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * example use of Iterable.
 *
 * @author Roedy Green, Canadian Mind Products
 * @version 1.0 2009-01-01 - initial version
 * @since 2009-01-01
 */
public final class TestIterable implements Iterable<String>
    {
    // ------------------------------ FIELDS ------------------------------

    /**
     * internal ArrayList of seed varieties
     */
    private final ArrayList<String> a = new ArrayList<String>( 10 );
    // -------------------------- PUBLIC INSTANCE  METHODS --------------------------

    /**
     * iterator for entire class, just iterates over internal arrayList
     *
     * @return Iterator over entire class
     */
    public Iterator<String> iterator()
        {
        return a.iterator();
        }

    {
    // init when TestIterable object instantiated.
    a.add( "pinecone" );
    a.add( "apple seed" );
    a.add( "peach pit" );
    a.add( "cocoanut" );
    a.add( "acorn" );
    }

    // --------------------------- main() method ---------------------------

    /**
     * Sample code to TestIterable. Needs JDK 1.6+
     *
     * @param args not used
     */
    public static void main( String[] args )
        {
        TestIterable t = new TestIterable();
        for ( String s : t )
            {
            System.out.println( s );
            }
        }// end main
    }