package class8_1_RemoteControl.other; import java.util.Deque; import java.util.LinkedList; /** * This is a "helper" class that handles the details of invocation of specific commands * @author hornick * */ public class Invoker { private Deque stack = new LinkedList(); /** * constructor */ public Invoker() { } /** * tells this to execute its Command immediately */ public boolean invoke( Command command ) { if(null == command) { System.out.println("Errro!!!!"); } boolean status; if(command instanceof UndoCommand) { Command lastCommand = stack.pollFirst(); if(null != lastCommand) { status = lastCommand.unexecute(); } else { status = false; } } else { status = command.execute(); if(status) { stack.push(command); } } return status; } }