|
| 1 | +package seedu.address.logic.commands; |
| 2 | + |
| 3 | +import static java.util.Objects.requireNonNull; |
| 4 | + |
| 5 | +import seedu.address.commons.util.ToStringBuilder; |
| 6 | +import seedu.address.logic.Messages; |
| 7 | +import seedu.address.logic.commands.exceptions.CommandException; |
| 8 | +import seedu.address.model.Model; |
| 9 | +import seedu.address.model.SeplendidModel; |
| 10 | +import seedu.address.model.notes.Note; |
| 11 | +import seedu.address.seplendidui.UiUtil; |
| 12 | + |
| 13 | +/** |
| 14 | + * Deletes a note to the NoteList. |
| 15 | + */ |
| 16 | +public class NoteDeleteCommand extends NoteCommand { |
| 17 | + |
| 18 | + // Also available in abstract class LocalCourseCommand to support polymorphism |
| 19 | + public static final String NOTE_DELETE_MESSAGE_USAGE = COMMAND_WORD |
| 20 | + + " delete [index]: Deletes a note."; |
| 21 | + public static final String ACTION_WORD = "delete"; |
| 22 | + |
| 23 | + public static final String MESSAGE_SUCCESS = "Note deleted: %1$s"; |
| 24 | + |
| 25 | + private final Integer noteIndexToDelete; |
| 26 | + |
| 27 | + /** |
| 28 | + * Creates a NoteAddCommand to add the specified {@code Note} |
| 29 | + * |
| 30 | + * @param note The Note to be added into Storage. |
| 31 | + */ |
| 32 | + public NoteDeleteCommand(int note) { |
| 33 | + super(); |
| 34 | + requireNonNull(note); |
| 35 | + noteIndexToDelete = note; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * TBD: This stub is to be removed after morphing is complete. |
| 40 | + * |
| 41 | + * @param model {@code Model} which the command should operate on. |
| 42 | + * @return Nothing. |
| 43 | + * @throws CommandException Always. |
| 44 | + */ |
| 45 | + @Override |
| 46 | + public CommandResult execute(Model model) throws CommandException { |
| 47 | + throw new CommandException("TBD: this is a stub and should be removed after morph."); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public CommandResult execute(SeplendidModel seplendidModel) throws CommandException { |
| 52 | + requireNonNull(seplendidModel); |
| 53 | + |
| 54 | + Note deletedNote = seplendidModel.deleteNote(noteIndexToDelete); |
| 55 | + return new CommandResult(String.format(MESSAGE_SUCCESS, Messages.format(deletedNote)), |
| 56 | + UiUtil.ListViewModel.NOTE_LIST); |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + @Override |
| 61 | + public boolean equals(Object other) { |
| 62 | + if (other == this) { |
| 63 | + return true; |
| 64 | + } |
| 65 | + |
| 66 | + // instanceof handles nulls |
| 67 | + if (!(other instanceof NoteDeleteCommand)) { |
| 68 | + return false; |
| 69 | + } |
| 70 | + |
| 71 | + NoteDeleteCommand otherNoteDeleteCommand = (NoteDeleteCommand) other; |
| 72 | + return noteIndexToDelete.equals(otherNoteDeleteCommand.noteIndexToDelete); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public String toString() { |
| 77 | + return new ToStringBuilder(this) |
| 78 | + .add("noteToDelete", noteIndexToDelete) |
| 79 | + .toString(); |
| 80 | + } |
| 81 | +} |
0 commit comments