package class9_1_PhonbookGui_start.policy;//package pbook; import class9_1_PhonbookGui_start.phonebook.Entry; import class9_1_PhonbookGui_start.phonebook.PhoneBook; // top level policy operations for use from user interface public class Handler { protected History history = new History(); protected PhoneBook pb = new PhoneBook(); // add a new phone entry public void addEntry(String name, String phone_number) { history.doCommand(new AddCommand(pb, new Entry(name, phone_number))); } public void editEntry(String name, String newPhoneNumber) { // history.doCommand(new EditCmd(pb,name,newPhoneNumber)); } // remove an existing entry; does nothing if entry not there public void removeEntry(String name) { history.doCommand(new RemoveCommand(pb, name)); } // return the history public History getHistory() { return history; } // return the phone book public PhoneBook getPhoneBook() { return pb; } // undoes last command if there is one to undo, otherwise does nothing public void undo() { if (history.nextToUndo() != null) history.undo(); } // redo last undone command if there is one to do, otherwise does nothing public void redo() { if (history.nextToRedo() != null) history.redo(); } }