001package myhw3.data; 002 003import java.util.Map; 004import myhw3.command.Command; 005 006/** 007 * Implementation of command to clear the inventory. 008 * @see Data 009 */ 010final class CmdClear implements Command { 011 private InventorySet inventory; 012 private Map<Video,Record> oldvalue; 013 CmdClear(InventorySet inventory) { 014 this.inventory = inventory; 015 } 016 public boolean run() { 017 if (oldvalue != null) { 018 return false; 019 } 020 oldvalue = inventory.clear(); 021 inventory.getHistory().add(this); 022 return true; 023 } 024 public void undo() { 025 inventory.replaceMap(oldvalue); 026 } 027 public void redo() { 028 oldvalue = inventory.clear(); 029 } 030}