package class7_3_RemoteControl_inClass.other; import java.util.*; /** * This is a "helper" class that handles the details of invocation of specific commands * @author hornick * */ public class Invoker { List doneCommands = new ArrayList<>(); /** * constructor */ public Invoker() { } /** * tells this to execute its Command immediately */ public boolean invoke( Command command ) { Thread worker = new Thread(()->command.execute()); worker.start(); doneCommands.add(command); return true; } /** * tells this to undo the last Command (if possible) */ public boolean undo() { Command lastCommand = doneCommands.remove(doneCommands.size()-1); lastCommand.unexecute(); return true; } }