macrocommand.java

来自「23种java设计模式」· Java 代码 · 共 33 行

JAVA
33
字号
package command;

import java.util.Stack;
import java.util.Iterator;

public class MacroCommand implements Command {
    // 柦椷偺廤崌
    private Stack commands = new Stack();
    // 幚峴
    public void execute() {
        Iterator it = commands.iterator();
        while (it.hasNext()) {
            ((Command)it.next()).execute();
        }
    }
    // 捛壛
    public void append(Command cmd) {
        if (cmd != this) {
            commands.push(cmd);
        }
    }
    // 嵟屻偺柦椷傪嶍彍
    public void undo() {
        if (!commands.empty()) {
            commands.pop();
        }
    }
    // 慡晹嶍彍
    public void clear() {
        commands.clear();
    }
}

⌨️ 快捷键说明

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