/**
  * Assigns a unique number to each task in a list of list of tasks starting from 1 within each
  * list of task
  *
  * @param list A list of list of tasks
  */
 private void numberTaskArrayList(ArrayList<ArrayList<Task>> list) {
   int taskNum = 1;
   for (ArrayList<Task> listT : list) {
     taskNum = 1;
     for (Task t : listT) {
       t.setTaskNumber(taskNum + "");
       taskNum++;
     }
   }
 }
Exemplo n.º 2
0
  /** Undo the command */
  @Override
  public void undo() {
    logger.log(Level.INFO, "Command UNDO 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 < userInput.getRecurList().size(); j++) {
          taskList.add(userInput.getRecurList().get(j));
          if (!displayList.equals(taskList)) {
            displayList.add(userInput.getRecurList().get(j));
          }
        }
        t.setRecurList(userInput.getRecurList());
      } else if (task.isRecurring()) {
        taskList.add(task);
        if (!displayList.equals(taskList)) {
          displayList.add(task);
        }
        Task t = task.getHead();
        t.getRecurList().add(task);
      } else {
        taskList.add(task);
        if (!displayList.equals(taskList)) {
          displayList.add(task);
        }
      }
    }
    storage.saveFile();

    feedback.setMessage(MSG_SUCCESS_UNDO);
  }
Exemplo n.º 3
0
  /**
   * Returns the type of task as a string description.
   *
   * @param task : The task type to be checked.
   * @return The string description of the task type.
   */
  private String getTaskTypeString(Task task) {
    String type;
    int taskType = task.getTaskType();

    switch (taskType) {
      case 1:
        type = TYPE_EVENT;
        break;

      case 2:
        type = TYPE_FLOATING;
        break;

      case 4:
        type = TYPE_DEADLINE;
        break;

      default:
        logger.log(Level.WARNING, "Invalid delete type.");
        type = null;
    }

    return type;
  }
Exemplo n.º 4
0
  /** 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]));
      }
    }
  }
Exemplo n.º 5
0
  /** 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);
  }