/*
 * @(#)WaitingActionList.java
 *
 * Last Modified: 9/15/01
 */

import java.awt.geom.AffineTransform;
import java.util.Collection;
import java.util.LinkedList;

/**
 * Linked list implementation of the <tt>List</tt> interface containing String actions and accompanying Object elements.  Implements all
 * optional list operations, but only permits a <code>String</code> with <code>Object</code> insertion.  In addition to implementing the <tt>List</tt> interface,
 * the <tt>WaitingActionList</tt> class extends the uniformly named methods within LinkedList to
 * <tt>get</tt>, <tt>remove</tt> and <tt>insert</tt> an element at the
 * beginning and end of the list.  These operations allow this list to be
 * used as a stack, queue, or double-ended queue (deque).<p>
 *
 * The primary purpose of the class is for the development of </tt>nextAction</tt>,
 * which calls the <code>waitingAction</code> method for the <code>headelement</code> passed and the
 * next action and accompanying Object element.
 *
 * @author  Corey Sanders
 * @version 1.4 9/15/01
 */

public class WaitingActionList extends LinkedList {


	/**
	 * LinkedList holding the <code>Object</code> elements for the WaitingActions.
	 */
	private LinkedList elements;

	/**
     * Constructs an empty list.
     */
	public WaitingActionList() {
		super();
		elements = new LinkedList();
	}

    /**
     * Constructs a list containing the elements of the specified
     * collection, in the order they are returned by the collection's
     * iterator.
     *
     * @param actions the collection whose string actions are to be placed into this list as the String Actions.
     * @param elements the collection whose elements are to be places into the list as the Object elements.
     */
    public WaitingActionList(Collection actions, Collection elements) {
	 	super(actions);
	 	this.elements = new LinkedList(elements);
    }

	/**
     * Appends the given <code>String</code> at the end of this list.
     *
     * @param action the <code>String</code> representing an action, to be inserted at the beginning of this list.
     *
     * @return <tt>true</tt> (as per the general contract of
	 * <tt>Collection.add</tt>).
     */
	public boolean add(String action) {
		return this.add(action, new Integer(0));
	}

	/**
     * Appends the given <code>String</code> and <code>Object</code> at the end of this list.
     *
     * @param action the <code>String</code> representing an action, to be inserted at the beginning of this list.
     * @param element the <code>Object</code> to be inserted in reference to the action.
	 *
     * @return <tt>true</tt> (as per the general contract of
	 * <tt>Collection.add</tt>).
     */
	public boolean add(String action, Object element) {
		elements.add(element);
		return super.add(action);
	}

	/**
     * Inserts the specified <code>String</code> and <code>Object</code> at the specified position in this list.
     * Shifts the <code>String</code> and <code>Object</code> currently at that position (if any) and any
     * subsequent elements to the right (adds one to their indices).
     *
     * @param index the integer index representing the location to add the action and element.
     * @param action the <code>String</code> representing an action, to be inserted at the beginning of this list.
     * @param element the <code>Object</code> to be inserted in reference to the action.
     *
     * @throws IndexOutOfBoundsException if the specified index is out of
     *		  range (<tt>index &lt; 0 || index &gt; size()</tt>).
     */
	public void add(int index, String action, Object element) throws IndexOutOfBoundsException {
		elements.add(index, element);
		super.add(index, action);
	}

	/**
     * Inserts the given <code>String</code> and <code>Object</code> at the beggining of this list.
     *
     * @param action the <code>String</code> representing an action, to be inserted at the beginning of this list.
     * @param element the <code>Object</code> to be inserted in reference to the action.
     */
	public void addFirst(String action, Object element) {
		super.addFirst(action);
		elements.addFirst(element);
	}

	/**
     * Appends the given <code>String</code> and <code>Object</code> at the end of this list.
     *
     * @param action the <code>String</code> representing an action, to be inserted at the end of this list.
     * @param element the <code>Object</code> to be inserted in reference to the action.
     */
	public void addLast(String action, Object element) {
		super.addLast(action);
		elements.addLast(element);
	}


	/**
     * Gets the given <code>String</code> of the action at the beggining of this list.
     *
     * @return action the <code>String</code> representing the first action.
     */
	public String getFirstAction() {
		return (String)super.getFirst();
	}

	/**
	 * Calls the next action of the <code>ObjectHead</code> headelement, using the waitingAction command.
	 * The call to <code>waitingAction</code> <b>always</b> passes the element, even if the element is unnecssary to
	 * that operations.
	 *
	 * @param headTree the <code>TreeHead</code> element of the <code>Tree</code> to which the action occurs.
	 */
	public void nextAction(TreeHead headTree) {
		String action = (String)super.removeFirst();
		Object element = elements.removeFirst();

		headTree.waitingAction(action, element);
	}


}