forked from nusCS2113-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* aboutUsUpdate * WIP implementations Add tasks related model Add commands related to tasks * fix *imports * passed checkstyle test
- Loading branch information
Showing
16 changed files
with
508 additions
and
0 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
71 changes: 71 additions & 0 deletions
71
src/main/java/seedu/address/logic/commands/AddTaskCommand.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,71 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_BODY; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_END; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRIORITY; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_START; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import seedu.address.logic.CommandHistory; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.task.Task; | ||
|
||
/** | ||
* Adds a task to the task list. | ||
*/ | ||
public class AddTaskCommand extends Command { | ||
public static final String COMMAND_WORD = "task"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a task to the task list. \n" | ||
+ "Parameters: " | ||
+ PREFIX_NAME + "NAME " | ||
+ "[" + PREFIX_BODY + "BODY] " | ||
+ "[" + PREFIX_START + "START_DATETIME] " | ||
+ PREFIX_END + "END_DATETIME " | ||
+ PREFIX_PRIORITY + "PRIORITY " | ||
+ "[" + PREFIX_TAG + "TAG]...\n" | ||
+ "Example: " + COMMAND_WORD + " " | ||
+ PREFIX_NAME + "Submission " | ||
+ PREFIX_BODY + "CG2027_assign2 " | ||
+ PREFIX_START + "09/10_1700 " | ||
+ PREFIX_END + "16/10_1400 " | ||
+ PREFIX_PRIORITY + "HIGH " | ||
+ PREFIX_TAG + "IVLE"; | ||
|
||
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 toAdd; | ||
|
||
/** | ||
* Creates an AddCommand to add the specified {@code Person} | ||
*/ | ||
public AddTaskCommand(Task task) { | ||
requireNonNull(task); | ||
toAdd = task; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model, CommandHistory history) throws CommandException { | ||
requireNonNull(model); | ||
|
||
if (model.hasTask(toAdd)) { | ||
throw new CommandException(MESSAGE_DUPLICATE_TASK); | ||
} | ||
|
||
model.addTask(toAdd); | ||
model.commitAddressBook(); | ||
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof AddTaskCommand // instanceof handles nulls | ||
&& toAdd.equals(((AddTaskCommand) other).toAdd)); | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
src/main/java/seedu/address/logic/parser/AddTaskCommandParser.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,62 @@ | ||
package seedu.address.logic.parser; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_BODY; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_END; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_PRIORITY; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_START; | ||
import static seedu.address.logic.parser.CliSyntax.PREFIX_TAG; | ||
|
||
import java.util.Set; | ||
import java.util.stream.Stream; | ||
|
||
import seedu.address.logic.commands.AddTaskCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.tag.Tag; | ||
import seedu.address.model.task.Body; | ||
import seedu.address.model.task.DateTime; | ||
import seedu.address.model.task.Priority; | ||
import seedu.address.model.task.Task; | ||
import seedu.address.model.task.TaskName; | ||
|
||
/** | ||
* Parses input arguments and creates a new AddTaskCommand object | ||
*/ | ||
public class AddTaskCommandParser implements Parser<AddTaskCommand> { | ||
|
||
public AddTaskCommandParser() throws ParseException { | ||
} | ||
|
||
/** | ||
* Returns true if none of the prefixes contains empty {@code Optional} values in the given | ||
* {@code ArgumentMultimap}. | ||
*/ | ||
private static boolean arePrefixesPresent(ArgumentMultimap argumentMultimap, Prefix... prefixes) { | ||
return Stream.of(prefixes).allMatch(prefix -> argumentMultimap.getValue(prefix).isPresent()); | ||
} | ||
|
||
@Override | ||
public AddTaskCommand parse(String userInput) throws ParseException { | ||
ArgumentMultimap argMultimap = | ||
ArgumentTokenizer.tokenize(userInput, PREFIX_NAME, PREFIX_BODY, PREFIX_START, PREFIX_END, | ||
PREFIX_PRIORITY, PREFIX_TAG); | ||
|
||
if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_BODY, PREFIX_START, PREFIX_END, PREFIX_PRIORITY) | ||
|| !argMultimap.getPreamble().isEmpty()) { | ||
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddTaskCommand.MESSAGE_USAGE)); | ||
} | ||
|
||
TaskName taskName = ParserUtil.parseTaskName(argMultimap.getValue(PREFIX_NAME).get()); | ||
Body body = ParserUtil.parseBody(argMultimap.getValue(PREFIX_BODY).get()); | ||
DateTime startDateTime = ParserUtil.parseDateTime(argMultimap.getValue(PREFIX_START).get()); | ||
DateTime endDateTime = ParserUtil.parseDateTime(argMultimap.getValue(PREFIX_END).get()); | ||
Priority priority = ParserUtil.parsePriority(argMultimap.getValue(PREFIX_PRIORITY).get()); | ||
Set<Tag> tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); | ||
|
||
Task task = new Task(taskName, body, startDateTime, endDateTime, priority, tagList); | ||
|
||
return new AddTaskCommand(task); | ||
|
||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package seedu.address.model.task; | ||
|
||
/** | ||
* Represents a Task's datails in the task list . | ||
* Guarantees: immutable. | ||
*/ | ||
public class Body { | ||
|
||
public static final String MESSAGE_BODY_CONSTRAINTS = | ||
"Task body can take any values, and it should not be blank"; | ||
|
||
private String bodyString; | ||
|
||
public Body(String bodyString) { | ||
this.bodyString = bodyString; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return bodyString; | ||
} | ||
} |
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,30 @@ | ||
package seedu.address.model.task; | ||
|
||
/** | ||
* Represents a Task's start & end date time in the task list. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidDateTime(String)} | ||
*/ | ||
public class DateTime { | ||
public static final String MESSAGE_DATETIME_CONSTRAINTS = | ||
"Date & Time should only contain numbers, and it should be at least 4 digits long"; | ||
public static final String DATETIME_VALIDATION_REGEX = "\\d{4,}"; | ||
|
||
private String dateTimeString; | ||
|
||
public DateTime(String dateTimeString) { | ||
this.dateTimeString = dateTimeString; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid date & time. | ||
*/ | ||
public static boolean isValidDateTime(String test) { | ||
return true; | ||
//return test.matches(DATETIME_VALIDATION_REGEX); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return dateTimeString; | ||
} | ||
} |
Oops, something went wrong.