Skip to content

Commit

Permalink
Merge pull request #166 from CS2103AUG2016-F11-C1/fix-parse-istaskevent
Browse files Browse the repository at this point in the history
Fix parseIsTaskEvent
  • Loading branch information
louietyj committed Nov 5, 2016
2 parents 0ea1128 + 64dd751 commit 41892cd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package seedu.todo.commons.exceptions;

public class AmbiguousEventTypeException extends ParseException {
/**
* @param message should contain relevant information on the failed constraint(s)
*/
public AmbiguousEventTypeException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.function.Predicate;

import seedu.todo.commons.exceptions.AmbiguousEventTypeException;
import seedu.todo.commons.exceptions.InvalidNaturalDateException;
import seedu.todo.models.Event;
import seedu.todo.models.Task;
Expand Down Expand Up @@ -44,18 +45,52 @@ public static Map<String, String[]> getFilterTokenDefinitions() {
*
* If there is no eventType specified, we will filter both.
*
* <ol>
* <li>If no "task"/"event" token, and no eventStatus/taskStatus token, then filter both</li>
* <li>If no "task"/"event" token, and exactly one of eventStatus/taskStatus present, then use it to guess</li>
* <li>If "task" token found, then assert no eventStatus token</li>
* <li>If "event" token found, then assert no taskStatus token</li>
* <li>Assert that eventStatus and taskStatus tokens cannot both be present</li>
* </ol>
*
* @param parsedResult
* @return {isTask, isEvent}
*/
public static boolean[] parseIsTaskEvent(Map<String, String[]> parsedResult) {
public static boolean[] parseIsTaskEvent(Map<String, String[]> parsedResult) throws AmbiguousEventTypeException {
// Extract relevant params
String eventType = null;
if (parsedResult.get("eventType") != null) {
return new boolean[] { true, true };
} else if (parsedResult.get("eventType")[0].equals("task")
|| parsedResult.get("eventType")[0].equals("tasks")) {
return new boolean[] { true, false };
eventType = parsedResult.get("eventType")[0];
// Singularize
eventType = eventType.equals("events") ? "event" : eventType;
eventType = eventType.equals("tasks") ? "task" : eventType;
}
boolean taskStatusPresent = parsedResult.get("taskStatus") == null;
boolean eventStatusPresent = parsedResult.get("eventStatus") == null;

if (eventType == null) {
if (!taskStatusPresent && !eventStatusPresent) {
// Condition 1
return new boolean[] { true, true };
} else if (eventStatusPresent && !taskStatusPresent) {
// Condition 2 - Task
return new boolean[] { true, false };
} else if (taskStatusPresent && !eventStatusPresent) {
// Condition 2 - Event
return new boolean[] { false, true };
}
} else {
return new boolean[] { false, true };
if (eventType.equals("task") && !eventStatusPresent) {
// Condition 3
return new boolean[] { true, false };
} else if (eventType.equals("event") && !taskStatusPresent) {
// Condition 4
return new boolean[] { false, true };
}
}

// If we made it here, then at least one assertion was violated.
throw new AmbiguousEventTypeException("Couldn't determine if task or event!");
}


Expand Down

0 comments on commit 41892cd

Please sign in to comment.