Skip to content

Commit

Permalink
update testing, hope it works!
Browse files Browse the repository at this point in the history
  • Loading branch information
ghurabah93 committed Nov 2, 2016
1 parent b125f10 commit 76f7c67
Show file tree
Hide file tree
Showing 26 changed files with 776 additions and 552 deletions.
10 changes: 10 additions & 0 deletions src/main/java/seedu/task/logic/HistoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@
public class HistoryManager {

private ArrayList<RollBackCommand> undoList;

private ArrayList<RollBackCommand> redoList;

private ArrayList<String> previousCommandList;

public HistoryManager() {
undoList = new ArrayList<RollBackCommand>();
redoList = new ArrayList<RollBackCommand>();

previousCommandList = new ArrayList<String>();
}

public void setUndoList(ArrayList<RollBackCommand> undoList) {
this.undoList = undoList;
}

public void setRedoList(ArrayList<RollBackCommand> redoList) {
this.redoList = redoList;
}

public void setPreviousCommand(ArrayList<String> previousCommand) {
this.previousCommandList = previousCommand;
Expand All @@ -33,6 +40,9 @@ public ArrayList<RollBackCommand> getUndoList() {
return undoList;
}

public ArrayList<RollBackCommand> getRedoList() {
return redoList;
}

public ArrayList<String> getPreviousCommandList() {
return previousCommandList;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/seedu/task/logic/Logic.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public interface Logic {

/** Returns the undo list of commands */
ArrayList<RollBackCommand> getUndoList();

/** Returns the redo list of commands */
ArrayList<RollBackCommand> getRedoList();

/** Returns the list of previous commands */
ArrayList<String> getPreviousCommandList();
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/seedu/task/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public ObservableList<ReadOnlyTask> getFilteredTaskList() {
public ArrayList<RollBackCommand> getUndoList() {
return historyManager.getUndoList();
}

@Override
public ArrayList<RollBackCommand> getRedoList() {
return historyManager.getRedoList();
}

@Override
public ArrayList<String> getPreviousCommandList() {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/seedu/task/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public AddCommand(String name, String startTime, String endTime, String deadline
for (String tagName : tags) {
tagSet.add(new Tag(tagName));
}
this.toAdd = new Task(new Name(name), new StartTime(startTime), new EndTime(endTime), new Deadline(deadline), new UniqueTagList(tagSet), new Status(false, false, true));
this.toAdd = new Task(new Name(name), new StartTime(startTime), new EndTime(endTime), new Deadline(deadline), new UniqueTagList(tagSet), new Status(false, false, false));
}

@Override
Expand Down
138 changes: 103 additions & 35 deletions src/main/java/seedu/task/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,115 @@
*/
public class EditCommand extends Command {
public static final String COMMAND_WORD = "edit";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Edits the task identified by the index number used in the last task listing.\n"
+ "Parameters: INDEX TASKNAME at START_TIME to END_TIME [by DEADLINE] [#TAG...]\n"
+ "Example: " + COMMAND_WORD
+ " 4 night class at 08.00pm to 10.00pm by 12.00am";

+ ": Edits the task identified by the index number used in the last task listing.\n"
+ "Parameters: INDEX TASKNAME at START_TIME to END_TIME [by DEADLINE] [#TAG...]\n"
+ "Example: " + COMMAND_WORD
+ " 4 tag, school";
public static final String MESSAGE_EDIT_TASK_SUCCESS = "Edit Task: %1$s";

public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task manager";

public static final String EDIT_NAME = "name";
public static final String EDIT_START_TIME = "start";
public static final String EDIT_END_TIME = "end";
public static final String EDIT_DEADLINE = "deadline";
public static final String EDIT_TAG = "tag";
public final int targetIndex;
private final Task toEdit;


public EditCommand(int targetIndex, String name, String startTime, String endTime, String deadline, Set<String> tags) throws IllegalValueException {
final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(new Tag(tagName));
}
this.toEdit = new Task(new Name(name), new StartTime(startTime), new EndTime(endTime), new Deadline(deadline), new UniqueTagList(tagSet), new Status());
//private final Task toEdit;
private final String toEdit;
private final String toEditItem;
private final Set<String> toEditTags;

// public EditCommand(int targetIndex, String name, String startTime, String endTime, String deadline, Set<String> tags) throws IllegalValueException {
// final Set<Tag> tagSet = new HashSet<>();
// for (String tagName : tags) {
// tagSet.add(new Tag(tagName));
// }
// this.toEdit = new Task(new Name(name), new StartTime(startTime), new EndTime(endTime), new Deadline(deadline), new UniqueTagList(tagSet), new Status());
// this.targetIndex = targetIndex;
// }

//@@author A0152958R
public EditCommand(int targetIndex, String item, String editResult, Set<String> tags) throws IllegalValueException {
this.targetIndex = targetIndex;
this.toEdit = editResult;
this.toEditItem = item;
this.toEditTags = tags;

}






//@@author A0152958R
@Override
public CommandResult execute(boolean isUndo) {
public CommandResult execute(boolean isUndo){
assert model != null;
UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

if (lastShownList.size() < targetIndex) {
indicateAttemptToExecuteIncorrectCommand();
return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}

ReadOnlyTask currentTask = lastShownList.get(targetIndex - 1);
ReadOnlyTask editedTask = null;

Task toAdd = null;
final Set<Tag> tagSet = new HashSet<>();

switch(this.toEditItem){
case EDIT_NAME:
try{
toAdd = new Task(new Name(this.toEdit), currentTask.getStartTime(), currentTask.getEndTime(), currentTask.getDeadline(), currentTask.getTags(), currentTask.getStatus());
}catch(IllegalValueException e){
return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}
break;
case EDIT_START_TIME:
try{
toAdd = new Task(currentTask.getName(), new StartTime(this.toEdit), currentTask.getEndTime(), currentTask.getDeadline(), currentTask.getTags(), currentTask.getStatus());
}catch(IllegalValueException e){
return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}
break;
case EDIT_END_TIME:
try{
toAdd = new Task(currentTask.getName(), currentTask.getStartTime(), new EndTime(this.toEdit), currentTask.getDeadline(), currentTask.getTags(), currentTask.getStatus());
}catch(IllegalValueException e){
return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}
break;
case EDIT_DEADLINE:
try{
toAdd = new Task(currentTask.getName(), currentTask.getStartTime(), currentTask.getEndTime(), new Deadline(this.toEdit), currentTask.getTags(), currentTask.getStatus());
}catch(IllegalValueException e){
return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}
break;
case EDIT_TAG:
try{
for (String tagName : this.toEditTags) {
tagSet.add(new Tag(tagName));
}
toAdd = new Task(currentTask.getName(), currentTask.getStartTime(), currentTask.getEndTime(), currentTask.getDeadline(), new UniqueTagList(tagSet), currentTask.getStatus());
}catch(IllegalValueException e){
return new CommandResult("Invalid tag format");
}
break;
default:
try{
for (String tagName : this.toEditTags) {
tagSet.add(new Tag(tagName));
}
toAdd = new Task(currentTask.getName(), currentTask.getStartTime(), currentTask.getEndTime(), currentTask.getDeadline(), new UniqueTagList(tagSet), currentTask.getStatus());
}catch(IllegalValueException e){
return new CommandResult(MESSAGE_DUPLICATE_TASK);
}
}

try {
model.addTask(targetIndex - 1, toEdit);
model.addTask(targetIndex - 1, toAdd);
editedTask = lastShownList.get(targetIndex - 1);
} catch (UniqueTaskList.DuplicateTaskException e) {
try {
Expand All @@ -74,27 +142,27 @@ public CommandResult execute(boolean isUndo) {
assert false : "The target task cannot be missing";
}
return new CommandResult(MESSAGE_DUPLICATE_TASK);
}

}
try {
model.deleteTask(currentTask);
} catch (TaskNotFoundException e) {
assert false : "The target task cannot be missing";
}

if (isUndo == false) {
history.getUndoList().add(new RollBackCommand(COMMAND_WORD, toEdit, (Task) currentTask));
history.getUndoList().add(new RollBackCommand(COMMAND_WORD, toAdd, (Task) currentTask));
}
return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, toEdit));
}



@Override
public CommandResult execute(int index) {
return null;

}


}
75 changes: 75 additions & 0 deletions src/main/java/seedu/task/logic/commands/FavoriteCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package seedu.task.logic.commands;

import seedu.task.commons.core.Messages;
import seedu.task.commons.core.UnmodifiableObservableList;
import seedu.task.logic.RollBackCommand;
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.model.task.Task;
import seedu.task.model.task.UniqueTaskList;
import seedu.task.model.task.UniqueTaskList.TaskNotFoundException;

/**
* Favorite a task from the task manager.
* @@author A0147335E
*/
public class FavoriteCommand extends Command {

public static final String COMMAND_WORD = "fav";

public static final String MESSAGE_USAGE = COMMAND_WORD
+ ": Favorite the task identified by the index number used in the last task listing.\n"
+ "Parameters: INDEX TASKNAME\n"
+ "Example: " + COMMAND_WORD
+ " 4";

public static final String MESSAGE_FAVORITE_TASK_SUCCESS = "Favorite Task: %1$s";

public static final String MESSAGE_ALREADY_FAVORITED = "Task has already been favorited!";

public final int targetIndex;

public FavoriteCommand(int targetIndex) {
this.targetIndex = targetIndex;
}

@Override
public CommandResult execute(boolean isUndo) {
assert model != null;
UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

if (lastShownList.size() < targetIndex) {
indicateAttemptToExecuteIncorrectCommand();
return new CommandResult(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX);
}

ReadOnlyTask currentTask = lastShownList.get(targetIndex - 1);
boolean oldStatus = currentTask.getStatus().getFavoriteStatus();

try {
model.deleteTask(currentTask);
} catch (TaskNotFoundException tnfe) {
assert false : "The target task cannot be missing";
}

Task newTask = new Task(currentTask);
newTask.getStatus().setFavoriteStatus(true);

try {
model.addTask(targetIndex - 1, newTask);
} catch (UniqueTaskList.DuplicateTaskException e) {}

if (oldStatus == newTask.getStatus().getFavoriteStatus()) {
return new CommandResult(MESSAGE_ALREADY_FAVORITED);
}

if (isUndo == false) {
history.getUndoList().add(new RollBackCommand(COMMAND_WORD, newTask, null));
}
return new CommandResult(String.format(MESSAGE_FAVORITE_TASK_SUCCESS, newTask.getName()));
}

@Override
public CommandResult execute(int index) {
return null;
}
}

0 comments on commit 76f7c67

Please sign in to comment.