forked from nus-cs2103-AY2021S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from AlexCQY/Add-Scheduler
Add scheduleCommand
- Loading branch information
Showing
26 changed files
with
306 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/main/java/seedu/address/logic/commands/ScheduleCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package seedu.address.logic.commands; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.time.DayOfWeek; | ||
import java.time.LocalDate; | ||
import java.util.function.Predicate; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.student.Student; | ||
|
||
/** | ||
* Finds and list all students with classes on a given date. | ||
* This is also the schedule of the user on that particular date. | ||
*/ | ||
public class ScheduleCommand extends Command { | ||
|
||
public static final String COMMAND_WORD = "schedule"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Given a date in the format of dd/mm/yy " | ||
+ "outputs all classes together with the respective student on the date" | ||
+ "and displays them as a list with index numbers.\n" | ||
+ "Parameters: DATE \n" | ||
+ "Example: " + COMMAND_WORD + " 27/10/20"; | ||
|
||
public static final String INCORRECT_DATE_FORMAT = "Date should be in the format dd/mm/yyyy"; | ||
public static final String EMPTY_DATE_MESSAGE = "Please input a date"; | ||
|
||
private final LocalDate dateToFindSchedule; | ||
|
||
public ScheduleCommand(LocalDate dateTime) { | ||
this.dateToFindSchedule = dateTime; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) { | ||
requireNonNull(model); | ||
// this date is given by the user, we extract out the day | ||
DayOfWeek day = this.dateToFindSchedule.getDayOfWeek(); | ||
|
||
// checks which student has the same day as the one given extracted out | ||
Predicate<Student> predicate = student -> student.getAdmin().getClassTime().isSameDay(day); | ||
|
||
// updates the list that is currently showed in the ui | ||
model.updateFilteredPersonList(predicate); | ||
|
||
return new CommandResult( | ||
String.format(Messages.MESSAGE_STUDENTS_LISTED_OVERVIEW, model.getFilteredPersonList().size())); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ScheduleCommand // instanceof handles nulls | ||
&& dateToFindSchedule.equals(((ScheduleCommand) other).dateToFindSchedule)); // state check | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/seedu/address/logic/parser/ScheduleCommandParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package seedu.address.logic.parser; | ||
|
||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
import seedu.address.logic.commands.ScheduleCommand; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
|
||
/** | ||
* Parses input arguments and creates a new ScheduleCommand object | ||
*/ | ||
public class ScheduleCommandParser implements Parser<ScheduleCommand> { | ||
|
||
private static final DateTimeFormatter INPUT_FORMAT = DateTimeFormatter.ofPattern("d/MM/yyyy"); | ||
|
||
/** | ||
* Parses the given {@code userInputDate} to a LocalDate object | ||
* and returns a ScheduleCommand with the LocalDate object for execution. | ||
* @throws ParseException if the user input does not conform the expected date format | ||
* and the input is an empty string | ||
*/ | ||
@Override | ||
public ScheduleCommand parse(String userInputDate) throws ParseException { | ||
requireNonNull(userInputDate); | ||
String trimmedUserInput = userInputDate.trim(); | ||
|
||
// check to see if input string is empty | ||
if (trimmedUserInput.isBlank()) { | ||
throw new ParseException(ScheduleCommand.EMPTY_DATE_MESSAGE); | ||
} | ||
|
||
try { | ||
LocalDate date = LocalDate.parse(trimmedUserInput, INPUT_FORMAT); | ||
return new ScheduleCommand(date); | ||
} catch (DateTimeParseException e) { | ||
throw new ParseException(ScheduleCommand.INCORRECT_DATE_FORMAT); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.