forked from nus-cs2103-AY2122S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
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 nus-cs2103-AY2122S1#79 from jovyntls/reminders-add…
…-date-parsing LGTM
- Loading branch information
Showing
13 changed files
with
185 additions
and
35 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
51 changes: 51 additions & 0 deletions
51
src/main/java/seedu/address/logic/commands/reminder/ReminderDeleteCommand.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,51 @@ | ||
package seedu.address.logic.commands.reminder; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.util.List; | ||
|
||
import seedu.address.commons.core.Messages; | ||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.Command; | ||
import seedu.address.logic.commands.CommandResult; | ||
import seedu.address.logic.commands.exceptions.CommandException; | ||
import seedu.address.model.Model; | ||
import seedu.address.model.reminder.Reminder; | ||
|
||
public class ReminderDeleteCommand extends Command { | ||
public static final String COMMAND_WORD = "deleter"; | ||
|
||
public static final String MESSAGE_USAGE = COMMAND_WORD | ||
+ ": Deletes the Reminder identified by the index number used in the displayed Reminder list.\n" | ||
+ "Parameters: INDEX (must be a positive integer)\n" | ||
+ "Example: " + COMMAND_WORD + " 1"; | ||
|
||
public static final String MESSAGE_DELETE_REMINDER_SUCCESS = "Deleted Reminder: %1$s"; | ||
|
||
private final Index targetReminderIndex; | ||
|
||
public ReminderDeleteCommand(Index targetReminderIndex) { | ||
this.targetReminderIndex = targetReminderIndex; | ||
} | ||
|
||
@Override | ||
public CommandResult execute(Model model) throws CommandException { | ||
requireNonNull(model); | ||
List<Reminder> lastShownList = model.getFilteredReminderList(); | ||
|
||
if (targetReminderIndex.getZeroBased() >= lastShownList.size()) { | ||
throw new CommandException(Messages.MESSAGE_INVALID_REMINDER_DISPLAYED_INDEX); | ||
} | ||
|
||
Reminder reminderToDelete = lastShownList.get(targetReminderIndex.getZeroBased()); | ||
model.deleteReminder(reminderToDelete); | ||
return new CommandResult(String.format(MESSAGE_DELETE_REMINDER_SUCCESS, reminderToDelete)); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ReminderDeleteCommand // instanceof handles nulls | ||
&& targetReminderIndex.equals(((ReminderDeleteCommand) other).targetReminderIndex)); // 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
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
29 changes: 29 additions & 0 deletions
29
src/main/java/seedu/address/logic/parser/reminder/ReminderDeleteCommandParser.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,29 @@ | ||
package seedu.address.logic.parser.reminder; | ||
|
||
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT; | ||
|
||
import seedu.address.commons.core.index.Index; | ||
import seedu.address.logic.commands.reminder.ReminderDeleteCommand; | ||
import seedu.address.logic.parser.Parser; | ||
import seedu.address.logic.parser.ParserUtil; | ||
import seedu.address.logic.parser.exceptions.ParseException; | ||
|
||
/** | ||
* Parses input arguments and creates a new ReminderDeleteCommand object | ||
*/ | ||
public class ReminderDeleteCommandParser implements Parser<ReminderDeleteCommand> { | ||
/** | ||
* Parses the given {@code String} of arguments in the context of the PersonDeleteCommand | ||
* and returns a PersonDeleteCommand object for execution. | ||
* @throws ParseException if the user input does not conform the expected format | ||
*/ | ||
public ReminderDeleteCommand parse(String args) throws ParseException { | ||
try { | ||
Index index = ParserUtil.parseIndex(args); | ||
return new ReminderDeleteCommand(index); | ||
} catch (ParseException pe) { | ||
throw new ParseException( | ||
String.format(MESSAGE_INVALID_COMMAND_FORMAT, ReminderDeleteCommand.MESSAGE_USAGE), pe); | ||
} | ||
} | ||
} |
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
56 changes: 56 additions & 0 deletions
56
src/main/java/seedu/address/model/reminder/ReminderStartDate.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,56 @@ | ||
package seedu.address.model.reminder; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
|
||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public class ReminderStartDate { | ||
public static final String MESSAGE_CONSTRAINTS = | ||
"Dates should be entered in YYYY-MM-DD format, e.g. 2021-5-23"; | ||
public static final String PARSE_DATE_CONSTRAINTS = "This date could not be parsed. Is it a valid date?"; | ||
|
||
/* | ||
* The date must be in YYYY-MM-DD format. | ||
*/ | ||
public static final String VALIDATION_REGEX = "\\d{4}-\\d{1,2}-\\d{1,2}"; | ||
public static final SimpleDateFormat PARSE_INPUT_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); | ||
public static final SimpleDateFormat PARSE_DATE_TO_STRING_FORMAT = new SimpleDateFormat("E, dd MMM yyyy"); | ||
|
||
|
||
public final Date startDate; | ||
|
||
/** | ||
* Constructs a {@code ReminderStartDate}. | ||
* | ||
* @param date A valid date in YYYY-MM-DD format. | ||
*/ | ||
public ReminderStartDate(Date date) { | ||
requireNonNull(date); | ||
startDate = date; | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid name. | ||
*/ | ||
public static boolean isValidDate(String test) { | ||
return test.matches(VALIDATION_REGEX); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return PARSE_DATE_TO_STRING_FORMAT.format(startDate); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
return other == this // short circuit if same object | ||
|| (other instanceof ReminderStartDate // instanceof handles nulls | ||
&& startDate.toString().equals(((ReminderStartDate) other).startDate.toString())); // state check | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return startDate.hashCode(); | ||
} | ||
} |
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