Skip to content

Commit

Permalink
Revert "Validate date"
Browse files Browse the repository at this point in the history
  • Loading branch information
nawri14 committed Nov 2, 2016
1 parent fd91818 commit 803845a
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 203 deletions.
5 changes: 2 additions & 3 deletions src/main/java/seedu/task/logic/commands/AddCommand.java
Expand Up @@ -17,7 +17,6 @@
import seedu.task.model.task.StartDate;
import seedu.task.model.task.Status;
import seedu.task.model.task.Task;
import seedu.task.model.task.TaskColor;
import seedu.task.model.task.TimeInterval;
import seedu.task.model.task.Title;
import seedu.task.model.task.UniqueTaskList;
Expand Down Expand Up @@ -65,7 +64,7 @@ public AddCommand(String title, String description, String startDate, String due

Task mainTask = new Task(new Title(title), new Description(description), new StartDate(startDate),
new DueDate(dueDate), new Interval(interval), new TimeInterval(timeInterval),
new Status("ONGOING"), new TaskColor("none"), new UniqueTagList(tagSet));
new Status("ONGOING"), new UniqueTagList(tagSet));
addTasksToList(mainTask);
}

Expand All @@ -82,7 +81,7 @@ private void addTasksToList(Task mainTask) {
tasksToAdd.add(new Task(mainTask.getTitle(), mainTask.getDescription(),
mainTask.getStartDateWithInterval(timeInterval * i),
mainTask.getDueDateWithInterval(timeInterval * i), mainTask.getInterval(),
mainTask.getTimeInterval(), new Status("ONGOING"), mainTask.getTaskColor(), mainTask.getTags()));
mainTask.getTimeInterval(), new Status("ONGOING"), mainTask.getTags()));
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/seedu/task/logic/commands/ClearCommand.java
Expand Up @@ -41,10 +41,8 @@ public CommandResult execute() {
private void saveModelForUndo() {
savedTasksForUndo = new ArrayList<Task>();
for (ReadOnlyTask task : model.getFilteredTaskList()) {
//@@author A0153751H
savedTasksForUndo.add(new Task(task.getTitle(), task.getDescription(), task.getStartDate(),
task.getDueDate(), task.getInterval(), task.getTimeInterval(), task.getStatus(), task.getTaskColor(), task.getTags()));
//@@author
task.getDueDate(), task.getInterval(), task.getTimeInterval(), task.getStatus(), task.getTags()));
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/seedu/task/logic/commands/DeleteCommand.java
Expand Up @@ -63,9 +63,7 @@ public CommandResult execute() {
* Save task for undo command before it is deleted.
*/
private void saveTaskForUndo(ReadOnlyTask task){
//@@author A0153751H
this.savedTaskForUndo = new Task(task.getTitle(), task.getDescription(), task.getStartDate(), task.getDueDate(), task.getInterval(), task.getTimeInterval(), task.getStatus(), task.getTaskColor(), task.getTags());
//@@author
this.savedTaskForUndo = new Task(task.getTitle(), task.getDescription(), task.getStartDate(), task.getDueDate(), task.getInterval(), task.getTimeInterval(), task.getStatus(), task.getTags());
}


Expand Down
4 changes: 1 addition & 3 deletions src/main/java/seedu/task/logic/commands/DoneCommand.java
Expand Up @@ -91,10 +91,8 @@ public CommandResult executeUndo() {
UnmodifiableObservableList<ReadOnlyTask> lastShownList = model.getFilteredTaskList();
int numberOfTasks = lastShownList.size();
ReadOnlyTask task = lastShownList.get(numberOfTasks - 1);
//@@author A0153751H
Task taskToAdd = new Task(task.getTitle(), task.getDescription(), task.getStartDate(), task.getDueDate(),
task.getInterval(), task.getTimeInterval(), task.getStatus(), task.getTaskColor(), task.getTags());
//@@author
task.getInterval(), task.getTimeInterval(), task.getStatus(), task.getTags());
taskToAdd.setStatus(new Status(targetStatus));
try {
model.deleteTask(task);
Expand Down
38 changes: 12 additions & 26 deletions src/main/java/seedu/task/logic/commands/EditCommand.java
Expand Up @@ -16,22 +16,20 @@
import seedu.task.model.task.ReadOnlyTask;
import seedu.task.model.task.StartDate;
import seedu.task.model.task.Task;
import seedu.task.model.task.TaskColor;
import seedu.task.model.task.Title;
import seedu.task.model.task.UniqueTaskList.DuplicateTaskException;
import seedu.task.model.task.UniqueTaskList.TaskNotFoundException;

/**
* Edits a task in the task manager.
*/
//@@author A0153751H

public class EditCommand extends Command {
public static final String COMMAND_WORD = "edit";
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits a task in the task manager. "
+ "Parameters: Index t/newTaskName d/description sd/startDate dd/dueDate c/color ts/tagSet"
+ "Parameters: Index t/newTaskName d/description sd/startDate dd/dueDate ts/tagSet"
+ "\nExample: " + COMMAND_WORD
+ " 1 t/newTaskName d/newDescription sd/11-11-2011 11:11 dd/11-11-2016 01:01 c/red ts/tag ts/tag2"
+ " 1 t/newTaskName d/newDescription sd/11-11-2011 dd/11-11-2016 ts/tag ts/tag2"
+ "\nNote: You must have at least one parameter other than the index of the task. Use multiple 'ts/' to list multiple tags.";

public final String MESSAGE_SUCCESS = "The data has been successfully edited.";
Expand All @@ -42,7 +40,7 @@ public class EditCommand extends Command {

private ReadOnlyTask selectedTask;
private Task copy, editedTask;
private String newTitle, description, startDate, dueDate, interval, timeInterval, taskColor;
private String newTitle, description, startDate, dueDate, interval, timeInterval;
private Set<String> tags;
private UnmodifiableObservableList<ReadOnlyTask> taskList;
private int taskIndex, realIndex;
Expand All @@ -60,7 +58,7 @@ public class EditCommand extends Command {
* @param timeInterval new time interval
* @param tags new set of tags
*/
public EditCommand(int index, String title, String description, String startDate, String dueDate, String interval, String timeInterval, String taskColor, Set<String> tags) {
public EditCommand(int index, String title, String description, String startDate, String dueDate, String interval, String timeInterval, Set<String> tags) {
taskIndex = index;
newTitle = title;
this.description = description;
Expand All @@ -69,7 +67,6 @@ public EditCommand(int index, String title, String description, String startDate
this.interval = interval;
this.timeInterval = timeInterval;
this.tags = tags;
this.taskColor = taskColor;
}


Expand Down Expand Up @@ -143,7 +140,7 @@ private void modifyList() throws TaskNotFoundException, DuplicateTaskException {
*/
public void edit(ReadOnlyTask task) throws IllegalValueException, ParseException{
copy = (Task) selectedTask;
iterateParams(newTitle, description, startDate, dueDate, interval, timeInterval, taskColor, tags);
iterateParams(newTitle, description, startDate, dueDate, interval, timeInterval, tags);
editedTask = copy;
}

Expand All @@ -159,7 +156,7 @@ public void edit(ReadOnlyTask task) throws IllegalValueException, ParseException
* @throws IllegalValueException if any values are illegal
* @throws ParseException if any values are illegal
*/
public void iterateParams(String name, String description, String startDate, String dueDate, String interval, String timeInterval, String taskColor, Set<String> tags) throws IllegalValueException, ParseException{
public void iterateParams(String name, String description, String startDate, String dueDate, String interval, String timeInterval, Set<String> tags) throws IllegalValueException, ParseException{
if (name != null) {
changeTitle(name);
}
Expand All @@ -172,9 +169,6 @@ public void iterateParams(String name, String description, String startDate, Str
if (dueDate != null) {
changeDueDate(dueDate);
}
if (taskColor != null && !taskColor.isEmpty()) {
changeTaskColor(taskColor);
}
if (tags != null && !tags.isEmpty()) {
changeTags(tags);
}
Expand All @@ -187,7 +181,7 @@ public void iterateParams(String name, String description, String startDate, Str
*/
public void changeTitle(String title) throws IllegalValueException {
Title newTitle = new Title(title);
copy = new Task(newTitle, copy.getDescription(), copy.getStartDate(), copy.getDueDate(), copy.getInterval(), copy.getTimeInterval(), copy.getStatus(), copy.getTaskColor(), copy.getTags());
copy = new Task(newTitle, copy.getDescription(), copy.getStartDate(), copy.getDueDate(), copy.getInterval(), copy.getTimeInterval(), copy.getStatus(), copy.getTags());
}

/**
Expand All @@ -197,7 +191,7 @@ public void changeTitle(String title) throws IllegalValueException {
*/
public void changeDescription(String description) throws IllegalValueException {
Description newDescription = new Description(description);
copy = new Task(copy.getTitle(), newDescription, copy.getStartDate(), copy.getDueDate(), copy.getInterval(), copy.getTimeInterval(), copy.getStatus(), copy.getTaskColor(), copy.getTags());
copy = new Task(copy.getTitle(), newDescription, copy.getStartDate(), copy.getDueDate(), copy.getInterval(), copy.getTimeInterval(), copy.getStatus(), copy.getTags());
}

/**
Expand All @@ -208,7 +202,7 @@ public void changeDescription(String description) throws IllegalValueException {
*/
public void changeStartDate(String startDate) throws IllegalValueException, ParseException {
StartDate newStartDate = new StartDate(startDate);
copy = new Task(copy.getTitle(), copy.getDescription(), newStartDate, copy.getDueDate(), copy.getInterval(), copy.getTimeInterval(), copy.getStatus(), copy.getTaskColor(), copy.getTags());
copy = new Task(copy.getTitle(), copy.getDescription(), newStartDate, copy.getDueDate(), copy.getInterval(), copy.getTimeInterval(), copy.getStatus(), copy.getTags());
}

/**
Expand All @@ -219,12 +213,7 @@ public void changeStartDate(String startDate) throws IllegalValueException, Pars
*/
public void changeDueDate(String dueDate) throws IllegalValueException, ParseException {
DueDate newDueDate = new DueDate(dueDate);
copy = new Task(copy.getTitle(), copy.getDescription(), copy.getStartDate(), newDueDate, copy.getInterval(), copy.getTimeInterval(), copy.getStatus(), copy.getTaskColor(), copy.getTags());
}

public void changeTaskColor(String taskColor) throws IllegalValueException {
TaskColor color = new TaskColor(taskColor);
copy = new Task(copy.getTitle(), copy.getDescription(), copy.getStartDate(), copy.getDueDate(), copy.getInterval(), copy.getTimeInterval(), copy.getStatus(), color, copy.getTags());
copy = new Task(copy.getTitle(), copy.getDescription(), copy.getStartDate(), newDueDate, copy.getInterval(), copy.getTimeInterval(), copy.getStatus(), copy.getTags());
}

/**
Expand All @@ -237,18 +226,15 @@ public void changeTags(Set<String> tags) throws IllegalValueException {
for (String tagName : tags) {
newTags.add(new Tag(tagName));
}
copy = new Task(copy.getTitle(), copy.getDescription(), copy.getStartDate(), copy.getDueDate(), copy.getInterval(), copy.getTimeInterval(), copy.getStatus(), copy.getTaskColor(), new UniqueTagList(newTags));
copy = new Task(copy.getTitle(), copy.getDescription(), copy.getStartDate(), copy.getDueDate(), copy.getInterval(), copy.getTimeInterval(), copy.getStatus(), new UniqueTagList(newTags));
}
//@@author

//@@author A0153411W
/**
* Save task which is edited to restore it for undo command
*/
private void saveTaskForUndo(ReadOnlyTask task){
//@@author A0153751H
this.savedTaskForUndo = new Task(task.getTitle(), task.getDescription(), task.getStartDate(), task.getDueDate(), task.getInterval(), task.getTimeInterval(), task.getStatus(), task.getTaskColor(), task.getTags());
//@@author
this.savedTaskForUndo = new Task(task.getTitle(), task.getDescription(), task.getStartDate(), task.getDueDate(), task.getInterval(), task.getTimeInterval(), task.getStatus(), task.getTags());
}

/**
Expand Down
17 changes: 3 additions & 14 deletions src/main/java/seedu/task/logic/parser/Parser.java
Expand Up @@ -63,11 +63,8 @@ public class Parser {
public static final Prefix dueDatePrefix = new Prefix(" dd/", true);
public static final Prefix intervalPrefix = new Prefix(" i/", true);
public static final Prefix timeIntervalPrefix = new Prefix(" ti/", true);
public static final Prefix tagArgumentsPrefix = new Prefix(" t/");
//@@author

public static final Prefix tagArgumentsPrefix = new Prefix(" t/");

//@@author A0153751H
private static final Pattern TASK_DATA_ARGS_FORMAT_EDIT = // '/' forward slashes are reserved for delimiter prefixes
Pattern.compile("(?<index>[^/]+)"
+ "(( t/(?<newTitle>[^/]+))|"
Expand All @@ -76,7 +73,6 @@ public class Parser {
+ "( dd/(?<dueDate>[^/]+))|"
+ "( i/(?<interval>[^/]+))|"
+ "( ti/(?<timeInterval>[^/]+))|"
+ "( c/(?<taskColor>[^/]+))|"
+ "(?<tagArguments>(?: ts/[^/]+)*))+?");
//@@author

Expand Down Expand Up @@ -268,15 +264,13 @@ private String isInputPresent(String input) {
* @param args full command args string
* @return the prepared command
*/
//@@author A0153751H
private Command prepareEdit(String args) {
final Matcher matcher = TASK_DATA_ARGS_FORMAT_EDIT.matcher(args.trim());
// Validate arg string format
if (!matcher.matches()) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
} else if (matcher.group("newTitle")==null && matcher.group("description")==null && matcher.group("startDate")==null && matcher.group("dueDate")==null
&& matcher.group("interval")==null && matcher.group("timeInterval")==null && matcher.group("tagArguments")==null && matcher.group("taskColor")==null
&& matcher.group("taskColor").equalsIgnoreCase("cyan")) {
&& matcher.group("interval")==null && matcher.group("timeInterval")==null && matcher.group("tagArguments")==null) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
}
try {
Expand All @@ -288,7 +282,6 @@ private Command prepareEdit(String args) {
matcher.group("dueDate"),
matcher.group("interval"),
matcher.group("timeInterval"),
matcher.group("taskColor"),
getTagsFromArgs(matcher.group("tagArguments"))
);
} catch (NumberFormatException e) {
Expand All @@ -302,14 +295,12 @@ private Command prepareEdit(String args) {
matcher.group("dueDate"),
matcher.group("interval"),
matcher.group("timeInterval"),
matcher.group("taskColor"),
null);
} catch (IllegalValueException e) {
return new IncorrectCommand(String.format(MESSAGE_INVALID_COMMAND_FORMAT, EditCommand.MESSAGE_USAGE));
}
}
//@@author
//@@author A0153751H_reused

private static Set<String> getTagsFromArgs(String tagArguments) throws IllegalValueException {
// no tags
if (tagArguments.isEmpty()) {
Expand All @@ -319,8 +310,6 @@ private static Set<String> getTagsFromArgs(String tagArguments) throws IllegalVa
final Collection<String> tagStrings = Arrays.asList(tagArguments.replaceFirst(" ts/", "").split(" ts/"));
return new HashSet<>(tagStrings);
}
//@@author


private Set<String> toSet(Optional<List<String>> tagsOptional) {
List<String> tags = tagsOptional.orElse(Collections.emptyList());
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/seedu/task/model/task/ReadOnlyTask.java
Expand Up @@ -16,9 +16,6 @@ public interface ReadOnlyTask {
Interval getInterval();
TimeInterval getTimeInterval();
Status getStatus();
//@@author A0153751H
TaskColor getTaskColor();
//@@author
void setStatus(Status status);
//@@author
/**
Expand Down Expand Up @@ -75,6 +72,5 @@ default String tagsString() {
return buffer.substring(0, buffer.length() - separator.length());
}
}


}
12 changes: 2 additions & 10 deletions src/main/java/seedu/task/model/task/Task.java
Expand Up @@ -13,7 +13,6 @@
*/
//@@author A0153411W
//@@author A0148083A
//@@author A0153751H
public class Task implements ReadOnlyTask {


Expand All @@ -24,11 +23,10 @@ public class Task implements ReadOnlyTask {
private Interval interval;
private TimeInterval timeInterval;
private Status status;
private TaskColor color;
private UniqueTagList tags;

public Task(Title title, Description description, StartDate startDate, DueDate dueDate, Interval interval,
TimeInterval timeInterval, Status status, TaskColor color, UniqueTagList tags) {
TimeInterval timeInterval, Status status, UniqueTagList tags) {
assert !CollectionUtil.isAnyNull(title, description, startDate, dueDate, interval, timeInterval, tags);
this.title = title;
this.description = description;
Expand All @@ -37,7 +35,6 @@ public Task(Title title, Description description, StartDate startDate, DueDate d
this.interval = interval;
this.timeInterval = timeInterval;
this.status = status;
this.color = color;
this.tags = new UniqueTagList(tags); // protect internal tags from
// changes in the arg list
}
Expand All @@ -47,7 +44,7 @@ public Task(Title title, Description description, StartDate startDate, DueDate d
*/
public Task(ReadOnlyTask source) {
this(source.getTitle(), source.getDescription(), source.getStartDate(), source.getDueDate(),
source.getInterval(), source.getTimeInterval(), source.getStatus(), source.getTaskColor(), source.getTags());
source.getInterval(), source.getTimeInterval(), source.getStatus(), source.getTags());
}

@Override
Expand Down Expand Up @@ -85,11 +82,6 @@ public Status getStatus() {
return status;
}

@Override
public TaskColor getTaskColor() {
return color;
}

@Override
public void setStatus(Status status) {
this.status = status;
Expand Down

0 comments on commit 803845a

Please sign in to comment.