@Override
 public WorksheetCommandHistory clone() {
   WorksheetCommandHistory worksheetCommandHistory = new WorksheetCommandHistory();
   for (String worksheetId : getAllWorksheetId()) {
     worksheetCommandHistory.historyWorksheetMap.put(worksheetId, new CommandTagListMap());
   }
   for (ICommand command : getAllCommands()) {
     worksheetCommandHistory.insertCommandToHistory(command);
   }
   for (String worksheetId : getAllWorksheetId()) {
     CommandTagListMap newMap = worksheetCommandHistory.historyWorksheetMap.get(worksheetId);
     CommandTagListMap oldMap = this.historyWorksheetMap.get(worksheetId);
     if (oldMap != null && newMap != null) {
       if (oldMap.currentCommand != null) {
         newMap.currentCommand =
             new RedoCommandObject(
                 oldMap.currentCommand.getCommand(),
                 oldMap.currentCommand.getConsolidatedCommand());
       }
       if (oldMap.lastRedoCommand != null) {
         newMap.lastRedoCommand =
             new RedoCommandObject(
                 oldMap.lastRedoCommand.getCommand(),
                 oldMap.lastRedoCommand.getConsolidatedCommand());
       }
       newMap.stale = oldMap.stale;
     }
   }
   return worksheetCommandHistory;
 }
 public void clearCurrentCommand(String worksheetId) {
   if (worksheetId == null) {
     worksheetId = IMPORT_COMMANDS;
   }
   CommandTagListMap commandTagListMap = historyWorksheetMap.get(worksheetId);
   if (commandTagListMap != null) {
     commandTagListMap.currentCommand = null;
   }
 }
 public void setStale(String worksheetId, boolean stale) {
   if (worksheetId == null) {
     worksheetId = IMPORT_COMMANDS;
   }
   CommandTagListMap commandTagListMap = historyWorksheetMap.get(worksheetId);
   if (commandTagListMap != null) {
     commandTagListMap.stale = stale;
   }
 }
 public List<ICommand> getCommandsFromWorksheetId(String worksheetId) {
   List<ICommand> commands = new ArrayList<>();
   if (worksheetId == null) {
     worksheetId = IMPORT_COMMANDS;
   }
   CommandTagListMap map = historyWorksheetMap.get(worksheetId);
   if (map != null) {
     commands.addAll(map.getCommands());
   }
   return commands;
 }
 public void insertCommandToHistory(ICommand command) {
   String worksheetId = getWorksheetId(command);
   if (worksheetId == null) {
     worksheetId = IMPORT_COMMANDS;
   }
   CommandTagListMap commandTagListMap = historyWorksheetMap.get(worksheetId);
   if (commandTagListMap == null) {
     commandTagListMap = new CommandTagListMap();
     historyWorksheetMap.put(worksheetId, commandTagListMap);
   }
   commandTagListMap.addCommandToHistory(command);
 }
 public void setCurrentCommand(ICommand command, Pair<ICommand, Object> consolidatedCommand) {
   String worksheetId = getWorksheetId(command);
   if (worksheetId == null) {
     worksheetId = IMPORT_COMMANDS;
   }
   CommandTagListMap commandTagListMap = historyWorksheetMap.get(worksheetId);
   if (commandTagListMap == null) {
     commandTagListMap = new CommandTagListMap();
     historyWorksheetMap.put(worksheetId, commandTagListMap);
   }
   commandTagListMap.currentCommand = new RedoCommandObject(command, consolidatedCommand);
 }
  public void setLastRedoCommandObject(RedoCommandObject command) {

    String worksheetId = getWorksheetId(command.getCommand());
    if (worksheetId == null) {
      worksheetId = IMPORT_COMMANDS;
    }
    CommandTagListMap commandTagListMap = historyWorksheetMap.get(worksheetId);
    if (commandTagListMap == null) {
      commandTagListMap = new CommandTagListMap();
      historyWorksheetMap.put(worksheetId, commandTagListMap);
    }
    if (commandTagListMap.lastRedoCommand == null) {
      commandTagListMap.lastRedoCommand = command;
    }
  }