nyla.solutions.commas.MacroCommand Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nyla.solutions.commas Show documentation
Show all versions of nyla.solutions.commas Show documentation
Command pattern implementation for building services.
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;
}