Example #1
0
  /*
   * (non-Javadoc)
   *
   * @see logic.command.commandList.Command#execute()
   */
  public void execute() throws InvalidCommandException {

    assert (dataHandler != null);

    final String ERROR_MESSAGE = "Edit failed, invalid index";
    if (index == NOT_SET) {
      String indexString = StringHandler.getIntegerFromFirstSlot(task.getDescription());

      if (indexString == null) {}

      index = getIndex(indexString);

      if (!dataHandler.indexValid(index)) {
        throw new InvalidCommandException(ERROR_MESSAGE);
      }

      task.setDescription(StringHandler.removeFirstMatched(task.getDescription(), indexString));

      source = dataHandler.getTask(index);
    }

    if (!dataHandler.indexValid(index)) {
      throw new InvalidCommandException(ERROR_MESSAGE);
    }

    task = editSpecifiedField(source, task);

    dataHandler.editTask(source, task);
    undoHandler.addUndo(this);
  }
Example #2
0
  /**
   * Remove the some day keyword from the description
   *
   * @param toEditTask the task to edit
   * @param someDayKeyWords the keywords for someday
   */
  private void removeSomeDayKeyWord(Task toEditTask, String[] someDayKeyWords) {
    String matchedWord =
        StringHandler.getContainsWord(toEditTask.getDescription(), someDayKeyWords);
    String newDescription =
        StringHandler.removeFirstMatchedWord(toEditTask.getDescription(), matchedWord);

    toEditTask.setDescription(newDescription);
  }
Example #3
0
  /**
   * Check if someday is specified
   *
   * @param toEditTask the task to edit
   * @param someDayKeyWords the keywords for someday
   * @return if someday is specified
   */
  private boolean isSomeDaySpecified(Task toEditTask, String[] someDayKeyWords) {
    boolean somedaySpecified;

    if (toEditTask.getDescription() != null) {
      if (StringHandler.containsWord(toEditTask.getDescription(), someDayKeyWords)) {
        somedaySpecified = true;

      } else somedaySpecified = false;
    } else {
      somedaySpecified = false;
    }

    return somedaySpecified;
  }
Example #4
0
 /**
  * Parse integer from the string
  *
  * @param indexString the string which contains the index
  * @return the integer parsed from the string
  */
 private int getIndex(String indexString) {
   final int ARRAY_OFFSET = -1;
   return StringHandler.parseStringToInteger(indexString) + ARRAY_OFFSET;
 }