Skip to content

Commit

Permalink
Merge pull request #41 from CS2103AUG2016-W10-C1/parser/command/speci…
Browse files Browse the repository at this point in the history
…fy-item-type

Allow user to add and list 3 item types
  • Loading branch information
inaba1231 committed Oct 19, 2016
2 parents b34c510 + b597e6d commit 2feb93f
Show file tree
Hide file tree
Showing 17 changed files with 321 additions and 83 deletions.
1 change: 0 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="C:/Users/Jiayee/TaskMan/prettytime-4.0.1.Final.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions .settings/org.eclipse.buildship.core.prefs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
build.commands=org.eclipse.jdt.core.javabuilder
connection.arguments=
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.gradle.user.home=null
connection.java.home=null
connection.jvm.arguments=
connection.project.dir=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
/**
* Adds a Task to the task man.
*/
public class AddCommand extends Command {
public class DoCommand extends Command {

public static final String COMMAND_WORD = "add";
public static final String COMMAND_WORD = "do";

// todo, differed: let parameters be objects. we can easily generate the usage in that case
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a task to TaskMan. "
+ "Parameters: TITLE d/DEADLINE s/startDateTime, endDateTime f/frequency [t/TAG]...\n"
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a task to TaskMan.\n"
+ "Parameters: TITLE d/DEADLINE s/SCHEDULE f/FREQUENCY [t/TAG]...\n"
+ "Example: " + COMMAND_WORD
+ " Buy bday present for dad d/next fri 1800 s/tdy 1800, tdy 2000 f/1 year t/Family";
+ " pay utility bills d/next fri 1800 s/tdy 1800, tdy 1830 f/1 month t/bills";

public static final String MESSAGE_SUCCESS = "New task added: %1$s";
public static final String MESSAGE_DUPLICATE_EVENT = "This task already exists in TaskMan";
Expand All @@ -31,7 +31,7 @@ public class AddCommand extends Command {
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public AddCommand(String title, String deadline, String schedule, String frequency, Set<String> tags)
public DoCommand(String title, String deadline, String schedule, String frequency, Set<String> tags)
throws IllegalValueException {
final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
Expand All @@ -56,7 +56,7 @@ public AddCommand(String title, String deadline, String schedule, String frequen
public CommandResult execute() {
assert model != null;
try {
model.addTask(toAdd);
model.addEvent(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
} catch (UniqueActivityList.DuplicateActivityException e) {
return new CommandResult(MESSAGE_DUPLICATE_EVENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ListCommand extends Command {
private final Set<String> tagNames;

public ListCommand(Set<String> keywords) {
this(Model.FilterMode.TASK_ONLY, keywords, new HashSet<>());
this(Model.FilterMode.DEADLINE_ONLY, keywords, new HashSet<>());
}

public ListCommand(Model.FilterMode filterMode, Set<String> keywords, Set<String> tags){
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/seedu/taskman/logic/commands/MarkCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package seedu.taskman.logic.commands;

import seedu.taskman.commons.exceptions.IllegalValueException;
import seedu.taskman.model.tag.Tag;
import seedu.taskman.model.tag.UniqueTagList;
import seedu.taskman.model.event.*;

import java.util.HashSet;
import java.util.Set;

/**
* Adds a Event to the task man.
*/
public class MarkCommand extends Command {

public static final String COMMAND_WORD = "mark";

// todo, differed: let parameters be objects. we can easily generate the usage in that case
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds an event to TaskMan.\n"
+ "Parameters: TITLE s/SCHEDULE f/FREQUENCY [t/TAG]...\n"
+ "Example: " + COMMAND_WORD
+ " star gazing s/tdy 2300, tdy 2359 f/1 week t/leisure";

public static final String MESSAGE_SUCCESS = "New event added: %1$s";
public static final String MESSAGE_DUPLICATE_EVENT = "This event already exists in TaskMan";

private final Event toAdd;

/**
* Convenience constructor using raw values.
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public MarkCommand(String title, String schedule, String frequency, Set<String> tags)
throws IllegalValueException {
final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(new Tag(tagName));
}
this.toAdd = new Event(
new Title(title),
new UniqueTagList(tagSet),
schedule == null
? null
: new Schedule(schedule),
frequency == null
? null
: new Frequency(frequency)
);
}

@Override
public CommandResult execute() {
assert model != null;
try {
model.addEvent(toAdd);
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
} catch (UniqueActivityList.DuplicateActivityException e) {
return new CommandResult(MESSAGE_DUPLICATE_EVENT);
}

}

}
53 changes: 44 additions & 9 deletions src/main/java/seedu/taskman/logic/parser/CommandParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public class CommandParser {
private static final Pattern TASK_INDEX_ARGS_FORMAT = Pattern.compile(Argument.TARGET_INDEX.pattern);

private enum ListFlag{
LIST_EVENT("e/", FilterMode.EVENT_ONLY),
LIST_SCHEDULE("s/", FilterMode.SCHEDULE_ONLY),
LIST_DEADLINE("d/", FilterMode.DEADLINE_ONLY),
LIST_FLOATING("f/", FilterMode.FLOATING_ONLY),
LIST_ALL("all/", FilterMode.ALL);

public final String flag;
Expand Down Expand Up @@ -79,12 +81,18 @@ public String toString(){
}
}

private static final Pattern TASK_ADD_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes
private static final Pattern TASK_DO_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes
Pattern.compile("" + Argument.TITLE
+ Argument.DEADLINE
+ Argument.SCHEDULE
+ Argument.FREQUENCY
+ Argument.TAG); // variable number of tags

private static final Pattern EVENT_MARK_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes
Pattern.compile("" + Argument.TITLE
+ Argument.SCHEDULE
+ Argument.FREQUENCY
+ Argument.TAG); // variable number of tags

// TODO: All fields currently compulsory
private static final Pattern TASK_EDIT_ARGS_FORMAT = // '/' forward slashes are reserved for delimiter prefixes
Expand Down Expand Up @@ -114,8 +122,11 @@ public Command parseCommand(String userInput) {
final String arguments = matcher.group("arguments");
switch (commandWord) {

case AddCommand.COMMAND_WORD:
return prepareAdd(arguments);
case DoCommand.COMMAND_WORD:
return prepareDo(arguments);

case MarkCommand.COMMAND_WORD:
return prepareMark(arguments);

case EditCommand.COMMAND_WORD:
return prepareEdit(arguments);
Expand Down Expand Up @@ -152,14 +163,14 @@ public Command parseCommand(String userInput) {
* @param args full command args string
* @return the prepared command
*/
private Command prepareAdd(String args){
final Matcher matcher = TASK_ADD_ARGS_FORMAT.matcher(args.trim());
private Command prepareDo(String args){
final Matcher matcher = TASK_DO_ARGS_FORMAT.matcher(args.trim());
// Validate arg string format
if (!matcher.matches()) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddCommand.MESSAGE_USAGE));
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, DoCommand.MESSAGE_USAGE));
}
try {
return new AddCommand(
return new DoCommand(
matcher.group("title"),
matcher.group("deadline"),
matcher.group("schedule"),
Expand All @@ -170,6 +181,30 @@ private Command prepareAdd(String args){
return new IncorrectCommand(ive.getMessage());
}
}

/**
* Parses arguments in the context of the mark event command.
*
* @param args full command args string
* @return the prepared command
*/
private Command prepareMark(String args){
final Matcher matcher = EVENT_MARK_ARGS_FORMAT.matcher(args.trim());
// Validate arg string format
if (!matcher.matches()) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, MarkCommand.MESSAGE_USAGE));
}
try {
return new MarkCommand(
matcher.group("title"),
matcher.group("schedule"),
matcher.group("frequency"),
getTagsFromArgs(matcher.group("tagArguments"))
);
} catch (IllegalValueException ive) {
return new IncorrectCommand(ive.getMessage());
}
}

/**
* Extracts the new task's tags from the add command's tag arguments string.
Expand Down Expand Up @@ -291,7 +326,7 @@ private Command prepareList(String args) {
} else {
//filter
final String filter = matcher.group("filter");
Model.FilterMode filterMode = Model.FilterMode.TASK_ONLY;
Model.FilterMode filterMode = Model.FilterMode.DEADLINE_ONLY;
for(ListFlag listFlag: ListFlag.values()){
if(listFlag.flag.equals(filter)){
filterMode = listFlag.filterMode;
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/seedu/taskman/model/Model.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import seedu.taskman.commons.core.UnmodifiableObservableList;
import seedu.taskman.model.event.Activity;
import seedu.taskman.model.event.Event;
import seedu.taskman.model.event.Task;
import seedu.taskman.model.event.UniqueActivityList;

Expand All @@ -13,8 +14,9 @@
public interface Model {

public enum FilterMode {
TASK_ONLY,
EVENT_ONLY,
SCHEDULE_ONLY,
DEADLINE_ONLY,
FLOATING_ONLY,
ALL
}

Expand All @@ -27,8 +29,9 @@ public enum FilterMode {
/** Deletes the given activity. */
void deleteActivity(Activity target) throws UniqueActivityList.ActivityNotFoundException;

/** Adds the given task */
void addTask(Task task) throws UniqueActivityList.DuplicateActivityException;
//TODO Is this even needed?
/** Adds the given event */
void addEvent(Event task) throws UniqueActivityList.DuplicateActivityException;

void addActivity(Activity activity) throws UniqueActivityList.DuplicateActivityException;

Expand Down
12 changes: 8 additions & 4 deletions src/main/java/seedu/taskman/model/ModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import seedu.taskman.commons.exceptions.IllegalValueException;
import seedu.taskman.commons.util.StringUtil;
import seedu.taskman.model.event.Activity;
import seedu.taskman.model.event.Event;
import seedu.taskman.model.event.Task;
import seedu.taskman.model.event.UniqueActivityList;
import seedu.taskman.model.event.UniqueActivityList.ActivityNotFoundException;
Expand Down Expand Up @@ -72,8 +73,8 @@ public synchronized void deleteActivity(Activity target) throws ActivityNotFound
}

@Override
public synchronized void addTask(Task task) throws UniqueActivityList.DuplicateActivityException {
taskMan.addTask(task);
public synchronized void addEvent(Event event) throws UniqueActivityList.DuplicateActivityException {
taskMan.addEvent(event);
updateFilteredListToShowAll();
indicateTaskManChanged();
}
Expand Down Expand Up @@ -152,8 +153,11 @@ private class ActivityQualifier implements Qualifier {
public boolean run(Activity activity) {
// (fit task/event type && (no keyword || contain a keyword) && (no tag || contain a tag))
return (filterMode == FilterMode.ALL
|| (filterMode == FilterMode.EVENT_ONLY && activity.getType()== Activity.ActivityType.EVENT)
|| (filterMode == FilterMode.TASK_ONLY && activity.getType() == Activity.ActivityType.TASK))
|| (filterMode == FilterMode.SCHEDULE_ONLY && activity.getSchedule().isPresent())
|| (filterMode == FilterMode.DEADLINE_ONLY && activity.getType() == Activity.ActivityType.TASK
&& activity.getDeadline().isPresent())
|| (filterMode == FilterMode.FLOATING_ONLY && activity.getType() == Activity.ActivityType.TASK
&& !activity.getDeadline().isPresent()))
&& (titleKeyWords == null || titleKeyWords.isEmpty() || titleKeyWords.stream()
.filter(keyword -> StringUtil.containsIgnoreCase(activity.getTitle().title, keyword))
.findAny()
Expand Down
23 changes: 12 additions & 11 deletions src/main/java/seedu/taskman/model/TaskMan.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import javafx.collections.ObservableList;
import seedu.taskman.commons.exceptions.IllegalValueException;
import seedu.taskman.model.event.Activity;
import seedu.taskman.model.event.Event;
import seedu.taskman.model.event.MutableTagsEvent;
import seedu.taskman.model.event.Status;
import seedu.taskman.model.event.Task;
Expand Down Expand Up @@ -81,26 +82,26 @@ public void resetData(ReadOnlyTaskMan newData) {
resetData(newData.getActivityList(), newData.getTagList());
}

//// task-level operations
//// event-level operations

/**
* Adds a task to TaskMan.
* Also checks the new task's tags and updates {@link #tags} with any new tags found,
* and updates the Tag objects in the task to point to those in {@link #tags}.
* Adds a event to TaskMan.
* Also checks the new event's tags and updates {@link #tags} with any new tags found,
* and updates the Tag objects in the event to point to those in {@link #tags}.
*
* @throws UniqueActivityList.DuplicateActivityException if an equivalent task already exists.
* @throws UniqueActivityList.DuplicateActivityException if an equivalent event already exists.
*/
public void addTask(Task task) throws UniqueActivityList.DuplicateActivityException {
syncTagsWithMasterList(task);
activities.add(new Activity(task));
public void addEvent(Event event) throws UniqueActivityList.DuplicateActivityException {
syncTagsWithMasterList(event);
activities.add(new Activity(event));
}

/**
* Adds an activity to TaskMan.
* Also checks the new task's tags and updates {@link #tags} with any new tags found,
* and updates the Tag objects in the task to point to those in {@link #tags}.
* Also checks the new activity's tags and updates {@link #tags} with any new tags found,
* and updates the Tag objects in the activity to point to those in {@link #tags}.
*
* @throws UniqueActivityList.DuplicateActivityException if an equivalent task already exists.
* @throws UniqueActivityList.DuplicateActivityException if an equivalent activity already exists.
*/
public void addActivity(Activity activity) throws UniqueActivityList.DuplicateActivityException {
syncTagsWithMasterList(activity);
Expand Down

0 comments on commit 2feb93f

Please sign in to comment.