forked from se-edu/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from cs2113-ay1819s2-t08-2/master
update remote repo
- Loading branch information
Showing
20 changed files
with
651 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ preferences.json | |
.DS_Store | ||
./screenshot*.png | ||
classes/ | ||
/data/ | ||
/bin/ | ||
src/main/resources/docs/ | ||
out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"persons" : [ { | ||
"name" : "Alex Yeoh", | ||
"phone" : "87438807", | ||
"email" : "alexyeoh@example.com", | ||
"address" : "Blk 30 Geylang Street 29, #06-40", | ||
"tagged" : [ "friends" ] | ||
}, { | ||
"name" : "Bernice Yu", | ||
"phone" : "99272758", | ||
"email" : "berniceyu@example.com", | ||
"address" : "Blk 30 Lorong 3 Serangoon Gardens, #07-18", | ||
"tagged" : [ "colleagues", "friends" ] | ||
}, { | ||
"name" : "Charlotte Oliveiro", | ||
"phone" : "93210283", | ||
"email" : "charlotte@example.com", | ||
"address" : "Blk 11 Ang Mo Kio Street 74, #11-04", | ||
"tagged" : [ "neighbours" ] | ||
}, { | ||
"name" : "David Li", | ||
"phone" : "91031282", | ||
"email" : "lidavid@example.com", | ||
"address" : "Blk 436 Serangoon Gardens Street 26, #16-43", | ||
"tagged" : [ "family" ] | ||
}, { | ||
"name" : "Irfan Ibrahim", | ||
"phone" : "92492021", | ||
"email" : "irfan@example.com", | ||
"address" : "Blk 47 Tampines Street 20, #17-35", | ||
"tagged" : [ "classmates" ] | ||
}, { | ||
"name" : "Roy Balakrishnan", | ||
"phone" : "92624417", | ||
"email" : "royb@example.com", | ||
"address" : "Blk 45 Aljunied Street 85, #11-31", | ||
"tagged" : [ "colleagues" ] | ||
}, { | ||
"name" : "John Doe", | ||
"phone" : "98765432", | ||
"email" : "johnd@example.com", | ||
"address" : "John street, block 123, #01-02", | ||
"tagged" : [ ] | ||
} ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"tasks": [ { | ||
"taskName" : "CS2113T Milestone V13", | ||
"deadlineDate" : "280319", | ||
"deadlineTime" : "2359", | ||
"tagged" : [ ] | ||
} ,{ | ||
|
||
"taskName" : "CS2101 OP2 ", | ||
"deadlineDate" : "290319", | ||
"deadlineTime" : "1000", | ||
"tagged" : [ ] | ||
} | ||
] | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/seedu/address/logic/commands/DeleteTaskCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.task.Task; | ||
|
||
import java.util.List; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
public class DeleteTaskCommand extends Command { | ||
public static final String COMMAND_WORD = "deleteTask"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes a task identified by the index number used in the displayed task list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_DELETE_TASK_SUCCESS = "Deleted Task: %1$s"; | ||
|
||
private final Index targetIndex; | ||
|
||
public DeleteTaskCommand(Index targetIndex) { | ||
this.targetIndex = targetIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) throws CommandException { | ||
requireNonNull(model); | ||
List<Task> lastShownList = model.getFilteredTaskList(); | ||
if (targetIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); | ||
} | ||
Task taskToDelete = lastShownList.get(targetIndex.getZeroBased()); | ||
model.deleteTask(taskToDelete); | ||
model.commitTaskList(); | ||
return new CommandResult(String.format(MESSAGE_DELETE_TASK_SUCCESS, taskToDelete)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof DeleteTaskCommand // instanceof handles nulls | ||
&& targetIndex.equals(((DeleteTaskCommand) other).targetIndex)); // state check | ||
|
||
} | ||
} |
169 changes: 169 additions & 0 deletions
169
src/main/java/seedu/address/logic/commands/EditTaskCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.commons.util.CollectionUtil; | ||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.tag.Tag; | ||
import seedu.address.model.task.DeadlineDate; | ||
import seedu.address.model.task.DeadlineTime; | ||
import seedu.address.model.task.Task; | ||
import seedu.address.model.task.TaskName; | ||
|
||
import java.util.*; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.*; | ||
import static seedu.address.model.Model.PREDICATE_SHOW_ALL_TASKS; | ||
|
||
public class EditTaskCommand extends Command{ | ||
public static final String COMMAND_WORD = "edit"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + | ||
": Edits the details of the task identified " | ||
+ "by the index number used in the displayed task list. " | ||
+ "Parameters: INDEX (must be a positive integer) " | ||
+ "[" + PREFIX_NAME + "NAME] " | ||
+ "[" + PREFIX_DEADLINE_TIME + "DeadlineTime] " | ||
+ "[" + PREFIX_DEADLINE_DATE + "DeadlineDate] " | ||
+ "[" + PREFIX_TAG + "TAG]...\n" | ||
+ "Example: " + COMMAND_WORD + "1" | ||
+ PREFIX_DEADLINE_DATE + "311219 " | ||
+ PREFIX_DEADLINE_TIME + "2359"; | ||
|
||
public static final String MESSAGE_EDIT_TASK_SUCCESS = "Edited Task: %1$s"; | ||
public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided"; | ||
public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task book"; | ||
|
||
private final Index index; | ||
private final EditTaskDescriptor editTaskDescriptor; | ||
|
||
public EditTaskCommand(Index index, EditTaskDescriptor editTaskDescriptor){ | ||
requireNonNull(index); | ||
requireNonNull(editTaskDescriptor); | ||
this.index = index; | ||
this.editTaskDescriptor = editTaskDescriptor; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) throws CommandException { | ||
requireNonNull(model); | ||
List<Task> lastShownList = model.getFilteredTaskList(); | ||
|
||
if (index.getZeroBased() >= lastShownList.size()){ | ||
throw new CommandException(Messages.MESSAGE_INVALID_TASK_DISPLAYED_INDEX); | ||
} | ||
Task taskToEdit = lastShownList.get(index.getZeroBased()); | ||
Task editedTask = createEditedTask(taskToEdit, editTaskDescriptor); | ||
if (!taskToEdit.isSameTask(editedTask) && model.hasTask(editedTask)){ | ||
throw new CommandException(MESSAGE_DUPLICATE_TASK); | ||
} | ||
model.setTask(taskToEdit, editedTask); | ||
model.updateFilteredTaskList(PREDICATE_SHOW_ALL_TASKS); | ||
model.commitTaskList(); | ||
return new CommandResult(String.format(MESSAGE_EDIT_TASK_SUCCESS, editedTask)); | ||
} | ||
|
||
private Task createEditedTask(Task taskToEdit, EditTaskDescriptor editTaskDescriptor) { | ||
assert taskToEdit != null; | ||
|
||
TaskName updatedTaskName = editTaskDescriptor.getTaskName().orElse(taskToEdit.getTaskName()); | ||
DeadlineTime updatedDeadlineTime = | ||
editTaskDescriptor.getDeadlineTime().orElse(taskToEdit.getDeadlineTime()); | ||
DeadlineDate updatedDeadlineDate = | ||
editTaskDescriptor.getDeadlineDate().orElse(taskToEdit.getDeadlineDate()); | ||
Set<Tag> updatedTags = | ||
editTaskDescriptor.getTags().orElse(taskToEdit.getTags()); | ||
return new Task(updatedTaskName, updatedDeadlineTime, updatedDeadlineDate, updatedTags); | ||
|
||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
// short circuit if same object | ||
if (other == this){ | ||
return true; | ||
} | ||
// instanceof handles nulls | ||
if (!(other instanceof EditTaskCommand)){ | ||
return false; | ||
} | ||
// state check | ||
EditTaskCommand e = (EditTaskCommand) other; | ||
return index.equals(e.index) | ||
&& editTaskDescriptor.equals(e.editTaskDescriptor); | ||
} | ||
|
||
|
||
|
||
public static class EditTaskDescriptor{ | ||
private TaskName taskName; | ||
private DeadlineTime deadlineTime; | ||
private DeadlineDate deadlineDate; | ||
private Set<Tag> tags; | ||
|
||
public EditTaskDescriptor(){} | ||
|
||
public EditTaskDescriptor(EditTaskDescriptor toCopy){ | ||
setTaskName(toCopy.taskName); | ||
setDeadlineDate(toCopy.deadlineDate); | ||
setDeadlineTime(toCopy.deadlineTime); | ||
setTags(toCopy.tags); | ||
} | ||
|
||
public boolean isAnyFieldEdited(){ return CollectionUtil.isAnyNonNull(taskName, deadlineDate, deadlineTime, tags); } | ||
|
||
public void setTaskName(TaskName taskName){ this.taskName = taskName;} | ||
public Optional<TaskName> getTaskName() {return Optional.ofNullable(taskName); } | ||
|
||
public void setDeadlineDate(DeadlineDate deadlineDate){ this.deadlineDate = deadlineDate;} | ||
public Optional<DeadlineDate> getDeadlineDate() { return Optional.ofNullable(deadlineDate);} | ||
|
||
public void setDeadlineTime(DeadlineTime deadlineTime){ this.deadlineTime = deadlineTime;} | ||
public Optional<DeadlineTime> getDeadlineTime() { return Optional.ofNullable(deadlineTime);} | ||
|
||
/** | ||
* Sets {@code tags} to this object's {@code tags}. | ||
* A defensive copy of {@code tags} is used internally. | ||
*/ | ||
public void setTags(Set<Tag> tags) { | ||
this.tags = (tags != null) ? new HashSet<>(tags) : null; | ||
} | ||
|
||
/** | ||
* Returns an unmodifiable tag set, which throws {@code UnsupportedOperationException} | ||
* if modification is attempted. | ||
* Returns {@code Optional#empty()} if {@code tags} is null. | ||
*/ | ||
public Optional<Set<Tag>> getTags() { | ||
return (tags != null) ? Optional.of(Collections.unmodifiableSet(tags)) : Optional.empty(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
// short circuit if same object | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof EditTaskDescriptor)) { | ||
return false; | ||
} | ||
|
||
// state check | ||
EditTaskDescriptor e = (EditTaskDescriptor) other; | ||
|
||
return getTaskName().equals(e.getTaskName()) | ||
&& getDeadlineDate().equals(e.getDeadlineDate()) | ||
&& getDeadlineTime().equals(e.getDeadlineTime()) | ||
&& getTags().equals(e.getTags()); | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/seedu/address/logic/parser/DeleteTaskCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.DeleteTaskCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
public class DeleteTaskCommandParser implements Parser<DeleteTaskCommand> { | ||
|
||
/** | ||
* Parses the given {@code String} of arguments in the context of the DeleteTaskCommand | ||
* and returns an DeleteTaskCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
@Override | ||
public DeleteTaskCommand parse(String args) throws ParseException { | ||
try{ | ||
Index index = ParserUtil.parseIndex(args); | ||
return new DeleteTaskCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, | ||
DeleteTaskCommand.MESSAGE_USAGE, pe)); | ||
} | ||
|
||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/seedu/address/logic/parser/EditTaskCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package seedu.address.logic.parser; | ||
|
||
|
||
import seedu.address.logic.commands.EditTaskCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
public class EditTaskCommandParser implements Parser<EditTaskCommand> { | ||
|
||
|
||
@Override | ||
public EditTaskCommand parse(String userInput) throws ParseException { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.