![JAR search and dependency download from the Maven repository](/logo.png)
nyla.solutions.global.patterns.command.MacroCommand Maven / Gradle / Ivy
package nyla.solutions.global.patterns.command;
import java.util.Collection;
import java.util.Iterator;
import nyla.solutions.global.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 - 2025 Weber Informatics LLC | Privacy Policy