Skip to content

Commit

Permalink
Merge pull request #8 from cs2113-ay1819s2-t08-2/master
Browse files Browse the repository at this point in the history
update remote repo
  • Loading branch information
weizhonglauw committed Apr 1, 2019
2 parents 80c69a9 + cc5e249 commit 080f2fd
Show file tree
Hide file tree
Showing 20 changed files with 651 additions and 103 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ preferences.json
.DS_Store
./screenshot*.png
classes/
/data/
/bin/
src/main/resources/docs/
out/
45 changes: 45 additions & 0 deletions data/addressbook.json
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" : [ ]
} ]
}
15 changes: 15 additions & 0 deletions data/tasklist.json
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" : [ ]
}
]
}
288 changes: 229 additions & 59 deletions docs/DeveloperGuide.adoc

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/main/java/seedu/address/commons/core/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class Messages {
public static final String MESSAGE_UNKNOWN_COMMAND = "Unknown command";
public static final String MESSAGE_INVALID_COMMAND_FORMAT = "Invalid command format! \n%1$s";
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
public static final String MESSAGE_INVALID_TASK_DISPLAYED_INDEX = "The task index provided is invalid";
// public static final String MESSAGE_INVALID_PURCHASE_DISPLAYED_INDEX = "The purchase index provided is invalid";
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class AddTaskCommand extends Command {
+ PREFIX_DEADLINE_TIME + "2359 "
+ PREFIX_TAG + "HIGH";

public static final String MESSAGE_SUCCESS = "New task added: ";
// public static final String MESSAGE_SUCCESS = "New task added: ";
public static final String MESSAGE_SUCCESS = "New task added: %1$s";
public static final String MESSAGE_DUPLICATE_TASK = "This task already exists in the task list";

private final Task newTask;
Expand All @@ -53,9 +54,9 @@ public CommandResult execute(Model model, CommandHistory history) throws Command
model.addTask(newTask);
model.commitTaskList();
model.commitAddressBook();
String toBePrinted = MESSAGE_SUCCESS + newTask.getTaskName() + " | "
+ "DEADLINE: " + newTask.getDeadlineDate() + ' ' + newTask.getDeadlineTime() + "HRS";
return new CommandResult(String.format(toBePrinted, newTask));
//String toBePrinted = MESSAGE_SUCCESS + newTask.getTaskName() + " | "
// + "DEADLINE: " + newTask.getDeadlineDate() + ' ' + newTask.getDeadlineTime() + "HRS";
return new CommandResult(String.format(MESSAGE_SUCCESS, newTask));
}


Expand Down
50 changes: 50 additions & 0 deletions src/main/java/seedu/address/logic/commands/DeleteTaskCommand.java
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 src/main/java/seedu/address/logic/commands/EditTaskCommand.java
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());
}


}


}
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ public Command parseCommand(String userInput) throws ParseException {
case AddTaskCommand.COMMAND_WORD:
return new AddTaskCommandParser().parse(arguments);


case DeleteTaskCommand.COMMAND_WORD:
return new DeleteTaskCommandParser().parse(arguments);


case AddPurchaseCommand.COMMAND_WORD:
return new AddPurchaseCommandParser().parse(arguments);

case ExpListCommand.COMMAND_WORD:
return new ExpListCommand();


case ClearExpListCommand.COMMAND_WORD:
return new ClearExpListCommand();

Expand Down
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));
}

}

}
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;
}
}

0 comments on commit 080f2fd

Please sign in to comment.