Skip to content

Commit

Permalink
Merge branch 'v0.2-dev' of https://github.com/CS2103AUG2016-T16-C3/main
Browse files Browse the repository at this point in the history
… into V0.2
  • Loading branch information
dfz2019 committed Oct 10, 2016
2 parents 04b4d4d + f034977 commit 2512aba
Show file tree
Hide file tree
Showing 39 changed files with 785 additions and 702 deletions.
2 changes: 1 addition & 1 deletion .classpath
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="seedu/manager/model/task/Time.java" kind="src" path="src/main/java">
<classpathentry excluding="seedu/manager/model/task/Time.java|seedu/manager/model/tag/Tag.java|seedu/manager/model/tag/UniqueTagList.java|seedu/manager/storage/XmlAdaptedTag.java" kind="src" path="src/main/java">
<attributes>
<attribute name="FROM_GRADLE_MODEL" value="true"/>
</attributes>
Expand Down
1 change: 0 additions & 1 deletion src/main/java/seedu/manager/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import seedu.manager.ui.Ui;
import seedu.manager.ui.UiManager;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ public TaskManagerChangedEvent(ReadOnlyTaskManager data){

@Override
public String toString() {
return "number of tasks " + data.getTaskList().size() + ", number of tags " + data.getTagList().size();
return "number of tasks " + data.getTaskList().size();
}
}
28 changes: 9 additions & 19 deletions src/main/java/seedu/manager/logic/commands/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package seedu.manager.logic.commands;

import java.util.HashSet;
import java.util.Set;
import java.util.HashMap;
import java.util.Optional;

import seedu.manager.commons.exceptions.IllegalValueException;
import seedu.manager.model.tag.Tag;
import seedu.manager.model.tag.UniqueTagList;
import seedu.manager.model.task.*;
import seedu.manager.model.task.Task.TaskProperties;

/**
* Adds a task to the task manager.
Expand All @@ -16,9 +15,9 @@ public class AddCommand extends Command {
public static final String COMMAND_WORD = "add";

public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a task to the task manager. "
+ "Parameters: DESC p/VENUE e/TIME a/PRIORITY [t/TAG]...\n"
+ "Parameters: DESC [<extensions>] \n"
+ "Example: " + COMMAND_WORD
+ " John Doe p/98765432 e/johnd@gmail.com a/med t/friends t/owesMoney";
+ " Dinner with Lancelot venue Avalon after 8:30pm before 9:00pm priority med";

public static final String MESSAGE_SUCCESS = "New task added: %1$s";
public static final String MESSAGE_DUPLICATE_PERSON = "This task already exists in the task manager";
Expand All @@ -30,21 +29,12 @@ public class AddCommand extends Command {
*
* @throws IllegalValueException if any of the raw values are invalid
*/
public AddCommand(String desc, String venue, /*String time,*/ String priority, String startTime, String endTime, Set<String> tags)
public AddCommand(HashMap<TaskProperties, Optional<TaskProperty>> properties)
throws IllegalValueException {
final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(new Tag(tagName));
if (!properties.get(TaskProperties.DESC).isPresent()) {
throw new IllegalValueException(MESSAGE_USAGE);
}
this.toAdd = new Task(
new Desc(desc),
new Venue(venue),
//new Time(time),
new Priority(priority),
new StartTime(startTime),
new EndTime(endTime),
new UniqueTagList(tagSet)
);
this.toAdd = new Task(properties);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public DeleteCommand(int targetIndex) {

@Override
public CommandResult execute() {
assert model != null;

UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

Expand Down
85 changes: 85 additions & 0 deletions src/main/java/seedu/manager/logic/commands/EditCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package seedu.manager.logic.commands;

import java.util.HashMap;
import java.util.Optional;

import seedu.manager.commons.core.Messages;
import seedu.manager.commons.core.UnmodifiableObservableList;
import seedu.manager.commons.exceptions.IllegalValueException;
import seedu.manager.model.task.ReadOnlyTask;
import seedu.manager.model.task.Task;
import seedu.manager.model.task.TaskProperty;
import seedu.manager.model.task.UniqueTaskList;
import seedu.manager.model.task.Task.TaskProperties;
import seedu.manager.model.task.UniqueTaskList.TaskNotFoundException;

/**
* Allows tasks to be edited. Uses an index to extract the task to be edited and changes its
* properties according to the new properties given
* @author varungupta
*
*/
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 (must be a positive integer) [DESC] [<extensions>]\n"
+ "Example: " + COMMAND_WORD + " 1 Dinner with Guinevere venue Under the Stars priority high";

public static final String MESSAGE_EDIT_PERSON_SUCCESS = "Edited Task: %1$s";
public static final String MESSAGE_DUPLICATE_PARAMS = "The new parameters are the same as before";

public final int targetIndex;

private final HashMap<TaskProperties, Optional<TaskProperty>> editedProperties;

public EditCommand(int targetIndex, HashMap<TaskProperties, Optional<TaskProperty>> editedProperties)
throws IllegalValueException {
this.targetIndex = targetIndex;
this.editedProperties = editedProperties;
}

@Override
public CommandResult execute() {
assert model != null;

UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();

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

ReadOnlyTask taskToEdit = lastShownList.get(targetIndex - 1);

try {
Task newTask = new Task(buildNewPropsFromOldAndEdited(taskToEdit.getProperties(), editedProperties));
model.addTask(newTask);
model.deleteTask(taskToEdit);
return new CommandResult(String.format(MESSAGE_EDIT_PERSON_SUCCESS, newTask));
} catch (TaskNotFoundException e) {
return new CommandResult("The target task cannot be missing");
} catch (UniqueTaskList.DuplicateTaskException e) {
return new CommandResult(MESSAGE_DUPLICATE_PARAMS);
}
}

private HashMap<TaskProperties, Optional<TaskProperty>> buildNewPropsFromOldAndEdited(
HashMap<TaskProperties, Optional<TaskProperty>> oldProperties,
HashMap<TaskProperties, Optional<TaskProperty>> editedProperties
) {
HashMap<TaskProperties, Optional<TaskProperty>> newProperties = new HashMap<>();

for (TaskProperties prop : TaskProperties.values()) {
if (editedProperties.get(prop).isPresent()) {
newProperties.put(prop, editedProperties.get(prop));
} else {
newProperties.put(prop, oldProperties.get(prop));
}
}

return newProperties;
}
}
177 changes: 177 additions & 0 deletions src/main/java/seedu/manager/logic/parser/ExtensionParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
package seedu.manager.logic.parser;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Optional;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import seedu.manager.commons.exceptions.IllegalValueException;
import seedu.manager.model.task.Desc;
import seedu.manager.model.task.EndTime;
import seedu.manager.model.task.Priority;
import seedu.manager.model.task.StartTime;
import seedu.manager.model.task.Task;
import seedu.manager.model.task.Task.TaskProperties;
import seedu.manager.model.task.TaskProperty;
import seedu.manager.model.task.Venue;

/**
* Used to parse extensions in the user input
* @author varungupta
*
*/
public class ExtensionParser {

public static enum ExtensionCmds {
VENUE("venue"), BEFORE("before"), AT("at"), AFTER("after"), PRIORITY("priority");

private String value;

private ExtensionCmds(String value) {
this.value = value;
}

public String getValue() {
return value;
}
};
private static final String EXTENSION_REGEX_OPTIONS;
private static final Pattern EXTENSIONS_DESC_FORMAT;
private static final Pattern EXTENSIONS_ARGS_FORMAT;
private static final Pattern EXTENSION_ARGS_FORMAT =
Pattern.compile("(?<commandWord>\\S+)(?<arguments>.*)");
private static final String EXTENSION_INVALID_FORMAT = "Extensions should have the form <extension> <arguments>";

public static final String EXTENSION_DUPLICATES = "Extensions should only contain one %1$s";

static {
EXTENSION_REGEX_OPTIONS = String.join("|", Arrays.stream(ExtensionCmds.values()).map(ex -> ex.getValue()).toArray(size -> new String[size]));
EXTENSIONS_DESC_FORMAT =
Pattern.compile("(^.*?(?=(?:(?:(\\s|^)(?:"
+ EXTENSION_REGEX_OPTIONS
+ ")\\s)|$)))");
EXTENSIONS_ARGS_FORMAT =
Pattern.compile("((?:"
+ EXTENSION_REGEX_OPTIONS
+ ").+?(?=(?:(?:\\s(?:"
+ EXTENSION_REGEX_OPTIONS
+ ")\\s)|$)))");
}

public ExtensionParser() {}

/**
* Build task from extensions
*/
public HashMap<Task.TaskProperties, Optional<TaskProperty>> getTaskProperties(String extensionsStr) throws IllegalValueException {
HashMap<Task.TaskProperties, Optional<TaskProperty>> properties = new HashMap<>();
extensionsStr = extensionsStr.trim();

for (Task.TaskProperties property : Task.TaskProperties.values()) {
properties.put(property, Optional.empty());
}

Matcher descMatcher = EXTENSIONS_DESC_FORMAT.matcher(extensionsStr);
if (descMatcher.find()) {
String desc = descMatcher.group().trim();
properties.put(TaskProperties.DESC,
desc.equals("") ? Optional.empty() : Optional.of(parseDesc(desc)));
if (descMatcher.find()) {
throw new IllegalValueException(EXTENSION_INVALID_FORMAT);
}
}

Matcher extMatcher = EXTENSIONS_ARGS_FORMAT.matcher(extensionsStr);
while (extMatcher.find()) {
parseSingleExtension(extMatcher.group(), properties);
}

return properties;
}

/**
* Parses a single extension
* @throws IllegalValueException
*/
private void parseSingleExtension(String extension, HashMap<Task.TaskProperties, Optional<TaskProperty>> properties)
throws IllegalValueException{
Matcher matcher = EXTENSION_ARGS_FORMAT.matcher(extension);
if (matcher.matches()) {
String extensionCommand = matcher.group("commandWord");
String arguments = matcher.group("arguments").trim();
ExtensionCmds matchedCommand = null;

for (ExtensionCmds ex : ExtensionCmds.values()) {
if (ex.value.equals(extensionCommand)) {
matchedCommand = ex;
break;
}
}

if (matchedCommand == null) {
throw new IllegalValueException(EXTENSION_INVALID_FORMAT);
}

switch (matchedCommand) {
case VENUE:
throwExceptionIfDuplicate(properties, TaskProperties.VENUE, ExtensionCmds.VENUE);
properties.put(TaskProperties.VENUE,
arguments.equals("") ? Optional.empty() : Optional.of(parseVenue(arguments)));
break;
case BEFORE:
throwExceptionIfDuplicate(properties, TaskProperties.ENDTIME, ExtensionCmds.BEFORE);
properties.put(TaskProperties.ENDTIME,
arguments.equals("") ? Optional.empty() : Optional.of(parseEndTime(arguments)));
break;
case AFTER:
throwExceptionIfDuplicate(properties, TaskProperties.STARTTIME, ExtensionCmds.AFTER);
properties.put(TaskProperties.STARTTIME,
arguments.equals("") ? Optional.empty() : Optional.of(parseStartTime(arguments)));
break;
case AT:
throwExceptionIfDuplicate(properties, TaskProperties.STARTTIME, ExtensionCmds.AT);
properties.put(TaskProperties.STARTTIME,
arguments.equals("") ? Optional.empty() : Optional.of(parseStartTime(arguments)));
break;
case PRIORITY:
throwExceptionIfDuplicate(properties, TaskProperties.PRIORITY, ExtensionCmds.PRIORITY);
properties.put(TaskProperties.PRIORITY,
arguments.equals("") ? Optional.empty() : Optional.of(parsePriority(arguments)));
break;
default:
throw new IllegalValueException(EXTENSION_INVALID_FORMAT);
}
} else {
throw new IllegalValueException(EXTENSION_INVALID_FORMAT);
}
}

private void throwExceptionIfDuplicate(HashMap<Task.TaskProperties, Optional<TaskProperty>> properties,
TaskProperties taskProperty, ExtensionCmds extensionCmd) throws IllegalValueException {
if (properties.get(taskProperty).isPresent()) {
throw new IllegalValueException(String.format(EXTENSION_DUPLICATES, extensionCmd.getValue()));
}
}

private TaskProperty parseDesc(String desc) throws IllegalValueException {

return new Desc(desc);
}

private TaskProperty parseVenue(String venue) throws IllegalValueException {
return new Venue(venue);
}

private TaskProperty parsePriority(String priority) throws IllegalValueException {
return new Priority(priority);
}

private TaskProperty parseStartTime(String time) throws IllegalValueException {
return new StartTime(time);
}

private TaskProperty parseEndTime(String time) throws IllegalValueException {
return new EndTime(time);
}
}

0 comments on commit 2512aba

Please sign in to comment.