1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- /*
- * 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<Object, Interface> 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();
- }
- }
|