/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package controller; import java.util.HashMap; import java.util.Stack; /** * * @author jechowma68968 */ public class Invoker { private HashMap commands; private Stack commandHistory; public Invoker() { commands = new HashMap<>(); commandHistory = new Stack(); } /** * * @param key ist das Object * @param value ist auch etwas */ public void addCommand(Object key, Interface value){ commands.put(key, value); } public void executeCommand(Object key){ commandHistory.push(key); commands.get(key).execute(); } public void undo(Object key){ if (commandHistory.isEmpty()){ return; } commands.get(commandHistory.pop()).undo(); } }