/*
 * Created on 21-Feb-2005
 */
package org.bodington.util;

import java.util.Iterator;

/**
 * This is an Iterator for when there is only going to be one item in the iterator and
 * a method needs to return an Iterator.
 * @author buckett
 */
public class SingleItemIterator implements Iterator
{

    Object item;
    boolean seen = false;
    
    /**
     * Create the iterator with the single item.
     * @param item The object to put in the iterator.
     */
    public SingleItemIterator(Object item)
    {
        this.item = item;
    }
    
    /** 
     * Attempts to remove the item. Currently doesn't work.
     * @see java.util.Iterator#remove()
     */
    public void remove()
    {
        throw new UnsupportedOperationException();
    }

    /**
     * Checks to see if there is another 
     * @see java.util.Iterator#hasNext()
     */
    public boolean hasNext()
    {
        return !seen;
    }

    /**
     * Gets the next item.
     * @see java.util.Iterator#next()
     */
    public Object next()
    {
        if (hasNext())
        {
            seen = true;
            return item;
        }
        return null;
    }

}
