コード例 #1
0
ファイル: Delete.java プロジェクト: cs2103jan2016-f13-2j/main
  /** Redo the command */
  @Override
  public void redo() {
    logger.log(Level.INFO, "Command REDO DELETE");
    taskList = storage.getTaskList();
    ArrayList<Task> displayList = MainLogic.getDisplayList();
    for (int i = 0; i < userInput.getTasksToDelete().size(); i++) {
      Task task = userInput.getTasksToDelete().get(i);

      if (task.isRecurring() && userInput.getIsAll()) {
        Task t = task.getHead();
        for (int j = 0; j < t.getRecurList().size(); j++) {
          taskList.remove(t.getRecurList().get(j));
          displayList.remove(t.getRecurList().get(j));
        }
        userInput.setRecurList(t.getRecurList());
        t.setRecurList(new ArrayList<Task>());
      } else if (task.isRecurring()) {
        taskList.remove(task);
        displayList.remove(task);
        Task t = task.getHead();
        t.getRecurList().remove(task);
      } else {
        taskList.remove(task);
        displayList.remove(task);
      }
    }
    storage.saveFile();

    feedback.setMessage(MSG_SUCCESS_REDO);
  }
コード例 #2
0
ファイル: Delete.java プロジェクト: cs2103jan2016-f13-2j/main
  /** Execute the command */
  @Override
  public void execute() {
    boolean success = false;

    logger.log(Level.INFO, "Command DELETE");
    taskList = storage.getTaskList();
    ArrayList<Task> displayList = MainLogic.getDisplayList();

    Task task = null;

    for (int i = 0; i < userInput.getTasksToDelete().size(); i++) {
      task = userInput.getTasksToDelete().get(i);
      if (task.isRecurring() && userInput.getIsAll()) {
        Task t = task.getHead();
        for (int j = 0; j < t.getRecurList().size(); j++) {
          taskList.remove(t.getRecurList().get(j));
          displayList.remove(t.getRecurList().get(j));
        }
        userInput.setRecurList(t.getRecurList());
        t.setRecurList(new ArrayList<Task>());
      } else if (task.isRecurring()) {
        taskList.remove(task);
        displayList.remove(task);
        Task t = task.getHead();
        t.getRecurList().remove(task);
      } else {
        taskList.remove(task);
        displayList.remove(task);
      }
    }

    success = true;

    if (!storage.saveFile()) {
      feedback.setMessage(MSG_FAIL_FILE_SAVE);
    } else if (success) {
      if (userInput.getDeleteNumber().size() > 1) {
        feedback.setMessage(MSG_SUCCESS_DELETE_MULTIPLE);
      } else {
        feedback.setMessage(
            String.format(
                MSG_SUCCESS_DELETE,
                getTaskTypeString(task),
                userInput.getDeleteNumber().get(0)[1]));
      }
    } else {
      if (userInput.getDeleteNumber().size() > 1) {
        feedback.setMessage(MSG_FAIL_INDEX_OOB_MULTIPLE);
        ;
      } else {
        feedback.setMessage(
            String.format(
                MSG_FAIL_INDEX_OOB,
                getTaskTypeString(task),
                userInput.getDeleteNumber().get(0)[1]));
      }
    }
  }