All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nyla.solutions.commas.MacroCommand Maven / Gradle / Ivy

The newest version!
package nyla.solutions.commas;



import java.util.Collection;
import java.util.Iterator;

import nyla.solutions.core.util.Debugger;

/**
 * This macro implementation for the command pattern
 * @author Gregory Green
 *
 */
public class MacroCommand implements Command
{	
	/**
	 * Default constructor
	 */
	public MacroCommand()
	{
	}// --------------------------------------------------------
	/**
	 * Default constructor
	 * @param collection the collection of commands
	 */
	public MacroCommand(Collection> collection)
	{
		this.setCommands(collection);
	}// --------------------------------------------------------
	/**
	 * Loop thru the commands and return the end results.
	 * Each the argument to each execute of the 
	 * @param source the input object to transform
	 * @return the altered object
	 */
	public ReturnType execute(InputType input)
	{
		if(commands == null || commands.isEmpty())
		{
			Debugger.printInfo("Source is commands empty. Returning null.");
			return null;
		}	    
		
		//loop through transformers
		ReturnType result = null;
		Command cmd = null;
		for(Iterator> i = commands.iterator();i.hasNext();)
		{
			cmd = i.next();
			result = cmd.execute(input);
		}
		return result;
	}// --------------------------------------------
	

	/**
	 * @return the commands
	 */
	public Collection> getCommands()
	{
		return commands;
	}


	/**
	 * @param commands the commands to set
	 */
	public void setCommands(Collection> commands)
	{
		this.commands = commands;
	}


	private Collection> commands = null;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy