1616import duke .commands .FindCommand ;
1717import duke .commands .InvalidInputCommand ;
1818import duke .commands .ListCommand ;
19+ import duke .commands .ReminderCommand ;
1920import duke .exceptions .InvalidActionException ;
2021import duke .exceptions .InvalidDateTimeFormatException ;
22+ import duke .exceptions .InvalidUrgencyDaysException ;
2123import duke .exceptions .MissingDeadlineException ;
2224import duke .exceptions .MissingDescriptionException ;
2325import duke .exceptions .MissingEventTimeException ;
@@ -39,26 +41,27 @@ public class Parser {
3941 private static final String TODO = "TODO" ;
4042 private static final String DEADLINE = "DEADLINE" ;
4143 private static final String EVENT = "EVENT" ;
44+ private static final String REMINDER = "REMINDER" ;
4245
4346 private static final ArrayList <String > validActions =
44- new ArrayList <>(Arrays .asList (BYE , LIST , DONE , DELETE , FIND , TODO , DEADLINE , EVENT ));
45-
46- public static ArrayList <String > getValidActions () {
47- return validActions ;
48- }
47+ new ArrayList <>(Arrays .asList (BYE , LIST , DONE , DELETE , FIND , REMINDER , TODO , DEADLINE , EVENT ));
4948
5049 /**
5150 * Parses a line of raw user input, converting it into a <code>Command</code> object that
5251 * handles all of the application's logic. Accordingly, the output <code>Command</code> object
53- * will be used to (1) alter the application's state, (2) computes responses to the users, and
54- * (3) determine whether to terminate the application.
52+ * will be used to:
53+ * (1) alter the application's state
54+ * (2) computes responses to the users
55+ * (3) determine whether to terminate the application
5556 *
5657 * @param input A line of raw user input.
5758 * @return Returns a <code>Command</code> object which will be used to execute the desired responses.
5859 */
5960 public static Command parse (String input ) {
61+ // If the input is valid, getExceptionMessage will return null.
62+ // If the input is invalid, getExceptionMessage will return an appropriate message to be displayed.
6063 String exceptionMessage = getExceptionMessage (input );
61- if (! exceptionMessage . equals ( "" ) ) {
64+ if (exceptionMessage != null ) {
6265 return new InvalidInputCommand (exceptionMessage );
6366 }
6467
@@ -76,6 +79,8 @@ public static Command parse(String input) {
7679 return new DoneCommand (Integer .parseInt (description ));
7780 case DELETE :
7881 return new DeleteCommand (Integer .parseInt (description ));
82+ case REMINDER :
83+ return new ReminderCommand (Integer .parseInt (description ));
7984 case FIND :
8085 return new FindCommand (description );
8186 case TODO :
@@ -184,6 +189,13 @@ private static boolean isInteger(String str) {
184189 return true ;
185190 }
186191
192+ private static boolean isPositiveInteger (String str ) {
193+ if (!isInteger (str )) {
194+ return false ;
195+ }
196+ return Integer .parseInt (str ) > 0 ;
197+ }
198+
187199 /**
188200 * Converts an input date or datetime string into a <code>LocalDateTime</code> object.
189201 *
@@ -238,6 +250,10 @@ private static String getExceptionMessage(String input) {
238250 throw new TaskNumberNotIntException ();
239251 }
240252
253+ if (action .equals (REMINDER ) && (!isPositiveInteger (description ))) {
254+ throw new InvalidUrgencyDaysException ();
255+ }
256+
241257 if (action .equals (DEADLINE ) && byDateTimeString .length () == 0 ) {
242258 throw new MissingDeadlineException ();
243259 }
@@ -259,10 +275,11 @@ private static String getExceptionMessage(String input) {
259275 | TaskNumberNotIntException
260276 | MissingDeadlineException
261277 | MissingEventTimeException
262- | InvalidDateTimeFormatException e ) {
278+ | InvalidDateTimeFormatException
279+ | InvalidUrgencyDaysException e ) {
263280 return e .getMessage ();
264281 }
265282
266- return "" ;
283+ return null ;
267284 }
268285}
0 commit comments