commandlist.java

来自「《JAVA与模式》附书中源代码」· Java 代码 · 共 44 行

JAVA
44
字号
package com.javapatterns.command.drawlines;

import java.util.Stack;

public class CommandList {
    private	Stack	executedCommands = new Stack();
    private	Stack	unexecutedCommands = new Stack();

private void _execute( Command command ) {
        command.execute();
        executedCommands.push( command );
    }

  public void execute( Command command ) {
        unexecutedCommands.removeAllElements();
        _execute( command );
    }

  public void unexecute() {
        Command command = (Command)executedCommands.pop();
        command.unexecute();
        unexecutedCommands.push( command );
    }

  public void reexecute() {
        Command command = (Command)unexecutedCommands.pop();
        _execute( command );
    }

  public void reset() {
        executedCommands.removeAllElements();
        unexecutedCommands.removeAllElements();
    }

    public boolean canUnexecuteCommand() {
        return !executedCommands.empty();
    }

    public boolean canReexecuteCommand() {
        return !unexecutedCommands.empty();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?