Skip to content

Commit

Permalink
Fix edit to work with list and find
Browse files Browse the repository at this point in the history
  • Loading branch information
teojm37 committed Oct 28, 2016
1 parent 3a4bd6a commit a3c169c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public CommandResult execute() {
}
storeOldDataChanged.add(oldData);
}
editedTask = model.editTask(targetIndex - 1, arguments);
} catch (TaskNotFoundException pnfe) {
editedTask = model.editTask(lastShownList.get(targetIndex - 1), arguments);
} catch (IndexOutOfBoundsException ioobe) {
indicateAttemptToExecuteIncorrectCommand();
return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
} catch (IllegalEditException iee) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/flexitrack/model/FlexiTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ public void addTask(Task p) throws DuplicateTaskException {
* @throws UniqueTaskList.DuplicateTaskException if an equivalent task already exists.
* @throws TaskNotFoundException if specified task is not found.
*/
public Task editTask(int taskToEdit, String[] args)
throws TaskNotFoundException, IllegalEditException, IllegalValueException {
public Task editTask(ReadOnlyTask taskToEdit, String[] args)
throws IllegalEditException, IllegalValueException {
return task.edit(taskToEdit, args);
}
//@@author
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/flexitrack/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ public interface Model {
*
* @throws TaskNotFoundException
*/
Task editTask(int taskToEdit, String[] args)
throws UniqueTaskList.TaskNotFoundException, UniqueTaskList.IllegalEditException, IllegalValueException;
Task editTask(ReadOnlyTask taskToEdit, String[] args)
throws UniqueTaskList.IllegalEditException, IllegalValueException;

//@@author
/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/seedu/flexitrack/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public void unmarkTask(ReadOnlyTask targetIndex) throws IllegalValueException {
* @throws UniqueTaskList.DuplicateTaskException if an equivalent task already exists.
* @throws TaskNotFoundException if specified task is not found.
*/
public Task editTask(int taskToEdit, String[] args)
throws TaskNotFoundException, IllegalEditException, IllegalValueException {
public Task editTask(ReadOnlyTask taskToEdit, String[] args)
throws IllegalEditException, IllegalValueException {
Task editedTask = flexiTracker.editTask(taskToEdit, args);
indicateFlexiTrackerChanged();
return editedTask;
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/seedu/flexitrack/model/task/UniqueTaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,24 +132,18 @@ public void sort(){
* edit
* -----------------------------------------------------
* finds the target task to be edited by the specified index and edits the task using the given argument array
* @param targetIndex
* @param taskToEdit
* @param args: Array of edit parameters
* @return The new duration if the item being edited is an event, or "" if it is a floating task or task
* @throws IllegalEditException
* @throws TaskNotFoundException
* @throws IllegalValueException
*/
public Task edit(int targetIndex, String[] args)
throws IllegalEditException, TaskNotFoundException, IllegalValueException {
assert targetIndex >= 0;
Task editTask;

try {
editTask = internalList.get(targetIndex);
} catch (IndexOutOfBoundsException ioobe) {
throw new TaskNotFoundException();
}

public Task edit(ReadOnlyTask taskToEdit, String[] args)
throws IllegalEditException, IllegalValueException {
assert taskToEdit != null;
int targetIndex = internalList.indexOf(taskToEdit);
Task editTask = internalList.get(targetIndex);
checkForIllegalFloatingTaskEdit(args, editTask);
editTaskParameters(editTask, args);
internalList.set(targetIndex, editTask);
Expand Down

0 comments on commit a3c169c

Please sign in to comment.