/*
 * @(#)CommandContainer.java	1.0 11-Apr-07
 *
 * IIT Bombay, 
 * Licensed under a Creative Commons Attribution-Noncommercial-Share Alike 2.5 License.
 */

package classes.shapes.commands;

import java.util.ArrayList;

import types.Command;
import interfaces.ICommandMediator;

/**
 * Holds the <tt>Command</tt> objects sent from other objects
 *
 * @author  Prathab, Mukesh
 * @version 1.0, 25-Mar-07
 * @see interfaces.ICommandMediator
 */
public class CommandContainer implements ICommandMediator {
	
	private ArrayList temporaryCommandList;
	private ArrayList permanentCommandList;
	private ArrayList objectList;
	
	public CommandContainer() {
		temporaryCommandList = new ArrayList();
		permanentCommandList = new ArrayList();
		objectList = new ArrayList();
		
	}
	/**
	 * Stores the commands in the list
	 * @param command command to be stored
	 * @param toPermanent if true the command is added to permanent list
	 * @see interfaces.ICommandMediator#sendCommand(types.Command)
	 */
	public void sendCommand(Command command, boolean toPermanent) {
		if(toPermanent) permanentCommandList.add(command);	
		else temporaryCommandList.add(command);
	}
	
	/**
	 * Stores the commands in a temporary list
	 * @param command command to be stored
	 * @see interfaces.ICommandMediator#sendCommand(types.Command)
	 */
	public void sendCommand(Command command) {
			temporaryCommandList.add(command);
	}
	
	/**
	 * Stores the objects which are interested to collect the commands automatically
	 * @param obj object to be added
	 */
	public void addObject(Object obj) {
		objectList.add(obj);
	}

	/**
	 * Removes the object from the object list 
	 * @param obj object to be removed
	 */
	public boolean removeObject(Object obj) {
		return objectList.remove(obj);
	}

	/**
	 * Sets the object list with command list
	 */
	public void setObjectList(ArrayList objList) {
		this.objectList = objList;
	}
	
	/**
	 * Returns command object list
	 */
	public ArrayList getObjectList() {
		return objectList;
	}
	/**
	 * Clears the temporary command list
	 */
	public void clearTempCommandList() {
		temporaryCommandList.clear();
	}
	
	/**
	 * Clears the permanent command list
	 */
	public void clearPermanentCommandList() {
		permanentCommandList.clear();
	}
	
	/**
	 * Returns temporary command list
	 */
	public ArrayList getTemporaryCommandList() {
		return temporaryCommandList;
	}
	/**
	 * Returns permanent command list
	 */
	public ArrayList getPermanentCommandList() {
		return permanentCommandList;
	}
}
