Skip to content

Commit 3cf9b03

Browse files
Merge pull request #52 from demitycho/scheduler
Scheduler Fixes #37 #38 #39 #43 #44
2 parents d9e3420 + f6f8584 commit 3cf9b03

21 files changed

+884
-4
lines changed

src/main/java/seedu/address/commons/core/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ public class Messages {
1010
public static final String MESSAGE_INVALID_MILESTONE_DISPLAYED_INDEX = "The milestone index provided is invalid";
1111
public static final String MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX = "The student index provided is invalid";
1212
public static final String MESSAGE_STUDENT_LISTED_OVERVIEW = "%1$d students listed!";
13+
public static final String MESSAGE_INVALID_START_END_TIME = "End time cannot be chronologically "
14+
+ "smaller than the Start time!";
1315

1416
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package seedu.address.logic.commands;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import static seedu.address.logic.parser.CliSyntax.PREFIX_DAY;
6+
import static seedu.address.logic.parser.CliSyntax.PREFIX_END_TIME;
7+
import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME;
8+
9+
import java.util.List;
10+
11+
import seedu.address.commons.core.Messages;
12+
import seedu.address.commons.core.index.Index;
13+
import seedu.address.logic.commands.exceptions.CommandException;
14+
import seedu.address.model.lesson.Day;
15+
import seedu.address.model.lesson.Time;
16+
import seedu.address.model.lesson.exceptions.DuplicateLessonException;
17+
import seedu.address.model.lesson.exceptions.InvalidLessonTimeSlotException;
18+
import seedu.address.model.student.Student;
19+
import seedu.address.model.student.exceptions.StudentNotFoundException;
20+
21+
/**
22+
* Adds a lesson to the schedule for a student in the address book.
23+
*/
24+
public class AddLessonCommand extends UndoableCommand {
25+
public static final String COMMAND_WORD = "addLesson";
26+
public static final String COMMAND_ALIAS = "a";
27+
28+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a lesson to the schedule, "
29+
+ "for a student who is in the address book. "
30+
+ "Parameters: "
31+
+ "INDEX " + PREFIX_DAY + " DAY "
32+
+ PREFIX_START_TIME + "START_TIME "
33+
+ PREFIX_END_TIME + "END_TIME \n"
34+
+ "Example: " + COMMAND_WORD + " 1 "
35+
+ PREFIX_DAY + "mon "
36+
+ PREFIX_START_TIME + "10:00 "
37+
+ PREFIX_END_TIME + "10:30 ";
38+
39+
public static final String MESSAGE_SUCCESS = "New lesson added for %1$s";
40+
public static final String MESSAGE_DUPLICATE_LESSON = "This lesson already exists in the schedule";
41+
public static final String MESSAGE_INVALID_TIME_SLOT = "This lesson clashes with another lesson in the schedule";
42+
43+
private final Index index;
44+
private final Day day;
45+
private final Time startTime;
46+
private final Time endTime;
47+
private Student studentToAddLesson;
48+
/**
49+
* Creates an AddLessonCommand to add the specified {@code Lesson}
50+
*/
51+
public AddLessonCommand(Index index, Day day, Time startTime, Time endTime) {
52+
requireNonNull(index);
53+
requireNonNull(day);
54+
requireNonNull(startTime);
55+
requireNonNull(endTime);
56+
57+
this.index = index;
58+
this.day = day;
59+
this.startTime = startTime;
60+
this.endTime = endTime;
61+
}
62+
63+
/**
64+
*
65+
* TODO add model.updateSchedule();
66+
* @throws CommandException
67+
*/
68+
@Override
69+
public CommandResult executeUndoableCommand() throws CommandException {
70+
try {
71+
model.addLesson(studentToAddLesson, day, startTime, endTime);
72+
} catch (InvalidLessonTimeSlotException iltse) {
73+
throw new CommandException(MESSAGE_INVALID_TIME_SLOT);
74+
} catch (DuplicateLessonException dle) {
75+
throw new CommandException(MESSAGE_DUPLICATE_LESSON);
76+
} catch (StudentNotFoundException pnfe) {
77+
throw new AssertionError("The target student cannot be missing");
78+
}
79+
return new CommandResult(String.format(MESSAGE_SUCCESS, studentToAddLesson.getName()));
80+
}
81+
82+
@Override
83+
protected void preprocessUndoableCommand() throws CommandException {
84+
List<Student> lastShownList = model.getFilteredStudentList();
85+
if (index.getZeroBased() >= lastShownList.size()) {
86+
throw new CommandException(Messages.MESSAGE_INVALID_STUDENT_DISPLAYED_INDEX);
87+
} else if (startTime.compareTo(endTime) >= 0) {
88+
throw new CommandException(Messages.MESSAGE_INVALID_START_END_TIME);
89+
}
90+
91+
studentToAddLesson = lastShownList.get(index.getZeroBased());
92+
}
93+
94+
@Override
95+
public boolean equals(Object other) {
96+
return other == this; // short circuit if same object
97+
}
98+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package seedu.address.logic.commands;
2+
3+
/**
4+
* Displays the user's schedule.
5+
*/
6+
public class ScheduleCommand extends Command {
7+
8+
public static final String COMMAND_WORD = "schedule";
9+
10+
public static final String MESSAGE_USAGE = COMMAND_WORD
11+
+ ": Views your weekly schedule";
12+
13+
public static final String MESSAGE_SUCCESS = "Schedule displayed";
14+
15+
public ScheduleCommand() {}
16+
17+
@Override
18+
public CommandResult execute() {
19+
model.getSchedule().print();
20+
return new CommandResult(MESSAGE_SUCCESS);
21+
}
22+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package seedu.address.logic.commands;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
import seedu.address.model.programminglanguage.ProgrammingLanguage;
7+
import seedu.address.model.student.Address;
8+
import seedu.address.model.student.Email;
9+
import seedu.address.model.student.Favourite;
10+
import seedu.address.model.student.Name;
11+
import seedu.address.model.student.Phone;
12+
import seedu.address.model.student.Student;
13+
import seedu.address.model.tag.Tag;
14+
import seedu.address.model.util.SampleDataUtil;
15+
16+
/**
17+
* A utility class to help with building Student objects.
18+
*/
19+
public class StudentBuilder {
20+
21+
public static final String DEFAULT_NAME = "Alice Pauline";
22+
public static final String DEFAULT_PHONE = "85355255";
23+
public static final String DEFAULT_EMAIL = "alice@gmail.com";
24+
public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111";
25+
public static final String DEFAULT_PROGRAMMING_LANGUAGE = "Java";
26+
public static final String DEFAULT_TAGS = "friends";
27+
public static final String DEFAULT_FAVOURITE = "false";
28+
29+
private Name name;
30+
private Phone phone;
31+
private Email email;
32+
private Address address;
33+
private ProgrammingLanguage programmingLanguage;
34+
private Set<Tag> tags;
35+
private Favourite favourite;
36+
37+
public StudentBuilder() {
38+
name = new Name(DEFAULT_NAME);
39+
phone = new Phone(DEFAULT_PHONE);
40+
email = new Email(DEFAULT_EMAIL);
41+
address = new Address(DEFAULT_ADDRESS);
42+
programmingLanguage = new ProgrammingLanguage(DEFAULT_PROGRAMMING_LANGUAGE);
43+
tags = SampleDataUtil.getTagSet(DEFAULT_TAGS);
44+
favourite = new Favourite(DEFAULT_FAVOURITE);
45+
}
46+
47+
/**
48+
* Initializes the StudentBuilder with the data of {@code studentToCopy}.
49+
*/
50+
public StudentBuilder(Student studentToCopy) {
51+
name = studentToCopy.getName();
52+
phone = studentToCopy.getPhone();
53+
email = studentToCopy.getEmail();
54+
address = studentToCopy.getAddress();
55+
programmingLanguage = studentToCopy.getProgrammingLanguage();
56+
tags = new HashSet<>(studentToCopy.getTags());
57+
favourite = studentToCopy.getFavourite();
58+
}
59+
60+
/**
61+
* Sets the {@code Name} of the {@code Student} that we are building.
62+
*/
63+
public StudentBuilder withName(String name) {
64+
this.name = new Name(name);
65+
return this;
66+
}
67+
68+
/**
69+
* Parses the {@code tags} into a {@code Set<Tag>} and set it to the {@code Student} that we are building.
70+
*/
71+
public StudentBuilder withTags(String ... tags) {
72+
this.tags = SampleDataUtil.getTagSet(tags);
73+
return this;
74+
}
75+
76+
/**
77+
* Sets the {@code Address} of the {@code Student} that we are building.
78+
*/
79+
public StudentBuilder withAddress(String address) {
80+
this.address = new Address(address);
81+
return this;
82+
}
83+
84+
/**
85+
* Sets the {@code Phone} of the {@code Student} that we are building.
86+
*/
87+
public StudentBuilder withPhone(String phone) {
88+
this.phone = new Phone(phone);
89+
return this;
90+
}
91+
92+
/**
93+
* Sets the {@code Email} of the {@code Student} that we are building.
94+
*/
95+
public StudentBuilder withEmail(String email) {
96+
this.email = new Email(email);
97+
return this;
98+
}
99+
100+
/**
101+
* Sets the {@code Favourite} of the {@code Student} that we are building.
102+
*/
103+
public StudentBuilder withFavourite(boolean val) {
104+
this.favourite = new Favourite(val);
105+
return this;
106+
}
107+
108+
/**
109+
* Sets the {@code programminglanguage} of the {@code Student} that we are building.
110+
*/
111+
public StudentBuilder withProgrammingLanguage(String progLang) {
112+
this.programmingLanguage = new ProgrammingLanguage(progLang);
113+
return this;
114+
}
115+
116+
public Student build() {
117+
return new Student(name, phone, email, address, programmingLanguage, tags, favourite);
118+
}
119+
120+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package seedu.address.logic.parser;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
6+
import static seedu.address.logic.parser.CliSyntax.PREFIX_DAY;
7+
import static seedu.address.logic.parser.CliSyntax.PREFIX_END_TIME;
8+
import static seedu.address.logic.parser.CliSyntax.PREFIX_START_TIME;
9+
10+
import seedu.address.commons.core.index.Index;
11+
12+
import seedu.address.commons.exceptions.IllegalValueException;
13+
import seedu.address.logic.commands.AddLessonCommand;
14+
import seedu.address.logic.parser.exceptions.ParseException;
15+
import seedu.address.model.lesson.Day;
16+
import seedu.address.model.lesson.Time;
17+
18+
/**
19+
* Parses input arguments and creates a new AddCommandCommand object
20+
*/
21+
public class AddLessonCommandParser implements Parser<AddLessonCommand> {
22+
23+
/**
24+
* Parses the given {@code String} of arguments in the context of the AddLessonCommand
25+
* and returns an AddLessonCommand object for execution.
26+
* @throws ParseException if the user input does not conform the expected format
27+
*/
28+
public AddLessonCommand parse(String args) throws ParseException {
29+
requireNonNull(args);
30+
ArgumentMultimap argMultimap =
31+
ArgumentTokenizer.tokenize(args, PREFIX_DAY, PREFIX_START_TIME, PREFIX_END_TIME);
32+
33+
Index index;
34+
Day day;
35+
Time startTime;
36+
Time endTime;
37+
38+
try {
39+
index = ParserUtil.parseIndex(argMultimap.getPreamble());
40+
} catch (IllegalValueException ive) {
41+
throw new ParseException(String.format(MESSAGE_INVALID_COMMAND_FORMAT, AddLessonCommand.MESSAGE_USAGE));
42+
}
43+
44+
try {
45+
day = ParserUtil.parseDay(argMultimap.getValue(PREFIX_DAY)).get();
46+
startTime = ParserUtil.parseTime(argMultimap.getValue(PREFIX_START_TIME)).get();
47+
endTime = ParserUtil.parseTime(argMultimap.getValue(PREFIX_END_TIME)).get();
48+
49+
} catch (IllegalValueException ive) {
50+
throw new ParseException(ive.getMessage(), ive);
51+
}
52+
//day = new Day("mon");
53+
return new AddLessonCommand(index, day, startTime, endTime);
54+
}
55+
56+
}

src/main/java/seedu/address/logic/parser/AddressBookParser.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.regex.Pattern;
88

99
import seedu.address.logic.commands.AddCommand;
10+
import seedu.address.logic.commands.AddLessonCommand;
1011
import seedu.address.logic.commands.AddMilestoneCommand;
1112
import seedu.address.logic.commands.AddTaskCommand;
1213
import seedu.address.logic.commands.ClearCommand;
@@ -22,6 +23,7 @@
2223
import seedu.address.logic.commands.ListCommand;
2324
import seedu.address.logic.commands.MoreInfoCommand;
2425
import seedu.address.logic.commands.RedoCommand;
26+
import seedu.address.logic.commands.ScheduleCommand;
2527
import seedu.address.logic.commands.SelectCommand;
2628
import seedu.address.logic.commands.UndoCommand;
2729
import seedu.address.logic.commands.UnfavouriteCommand;
@@ -58,6 +60,9 @@ public Command parseCommand(String userInput) throws ParseException {
5860
case AddCommand.COMMAND_ALIAS:
5961
return new AddCommandParser().parse(arguments);
6062

63+
case AddLessonCommand.COMMAND_WORD:
64+
return new AddLessonCommandParser().parse(arguments);
65+
6166
case AddMilestoneCommand.COMMAND_WORD:
6267
return new AddMilestoneCommandParser().parse(arguments);
6368

@@ -103,6 +108,9 @@ public Command parseCommand(String userInput) throws ParseException {
103108
case RedoCommand.COMMAND_WORD:
104109
return new RedoCommand();
105110

111+
case ScheduleCommand.COMMAND_WORD:
112+
return new ScheduleCommand();
113+
106114
case UnfavouriteCommand.COMMAND_WORD:
107115
return new UnfavouriteCommandParser().parse(arguments);
108116

src/main/java/seedu/address/logic/parser/CliSyntax.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ public class CliSyntax {
1212
public static final Prefix PREFIX_ADDRESS = new Prefix("a/");
1313
public static final Prefix PREFIX_PROGRAMMING_LANGUAGE = new Prefix("pl/");
1414
public static final Prefix PREFIX_TAG = new Prefix("t/");
15+
public static final Prefix PREFIX_START_TIME = new Prefix("st/");
16+
public static final Prefix PREFIX_END_TIME = new Prefix("et/");
17+
public static final Prefix PREFIX_DAY = new Prefix("d/");
1518
public static final Prefix PREFIX_DATE = new Prefix("d/");
1619
public static final Prefix PREFIX_DESCRIPTION = new Prefix("o/");
1720
public static final Prefix PREFIX_INDEX = new Prefix("i/");
1821
public static final Prefix PREFIX_MILESTONE_INDEX = new Prefix("m/");
22+
1923
}

0 commit comments

Comments
 (0)