Skip to content

Commit 0fb8cf5

Browse files
committed
Merge branch 'master' into branch-notes
2 parents c233024 + cb6227f commit 0fb8cf5

5 files changed

Lines changed: 95 additions & 3 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ public class Messages {
1010
public static final String MESSAGE_INVALID_PERSON_DISPLAYED_INDEX = "The person index provided is invalid";
1111
public static final String MESSAGE_PERSONS_LISTED_OVERVIEW = "%1$d persons listed!";
1212
public static final String MESSAGE_INVALID_MEETING_DISPLAYED_INDEX = "The meeting index provided is invalid";
13-
14-
13+
public static final String MESSAGE_INVALID_NOTE_DISPLAYED_INDEX = "The note index provided is invalid";
1514
}

src/main/java/seedu/address/logic/commands/notes/AddNoteCommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public class AddNoteCommand extends Command {
2424
+ "[" + PREFIX_PRIORITY + "PRIORITY]...\n"
2525
+ "Example: " + COMMAND_WORD + " "
2626
+ PREFIX_NAME + "Complete CS2103 Tutorial "
27-
+ PREFIX_PRIORITY + "5 ";
27+
+ PREFIX_PRIORITY + "5 \n"
28+
+ "Default priority is 1";
2829

2930
public static final String MESSAGE_SUCCESS = "New note added: %1$s";
3031
public static final String MESSAGE_DUPLICATE_NOTE = "This note already exists in the note book";
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package seedu.address.logic.commands.notes;
2+
3+
import static java.util.Objects.requireNonNull;
4+
5+
import java.util.List;
6+
7+
import seedu.address.commons.core.Messages;
8+
import seedu.address.commons.core.index.Index;
9+
import seedu.address.logic.commands.Command;
10+
import seedu.address.logic.commands.CommandResult;
11+
import seedu.address.logic.commands.exceptions.CommandException;
12+
import seedu.address.model.Model;
13+
import seedu.address.model.note.Note;
14+
15+
/**
16+
* Deletes a note identified using it's displayed index from the note book.
17+
*/
18+
public class DeleteNoteCommand extends Command {
19+
20+
public static final String COMMAND_WORD = "deleten";
21+
22+
public static final String MESSAGE_USAGE = COMMAND_WORD
23+
+ ": Deletes the note identified by the index number used in the displayed note list.\n"
24+
+ "Parameters: INDEX (must be a positive integer)\n"
25+
+ "Example: " + COMMAND_WORD + " 1";
26+
27+
public static final String MESSAGE_DELETE_NOTE_SUCCESS = "Deleted Note: %1$s";
28+
29+
private final Index targetIndex;
30+
31+
public DeleteNoteCommand(Index targetIndex) {
32+
this.targetIndex = targetIndex;
33+
}
34+
35+
@Override
36+
public CommandResult execute(Model model) throws CommandException {
37+
requireNonNull(model);
38+
List<Note> lastShownList = model.getFilteredNoteList();
39+
40+
if (targetIndex.getZeroBased() >= lastShownList.size()) {
41+
throw new CommandException(Messages.MESSAGE_INVALID_NOTE_DISPLAYED_INDEX);
42+
}
43+
44+
Note noteToDelete = lastShownList.get(targetIndex.getZeroBased());
45+
model.deleteNote(noteToDelete);
46+
return new CommandResult(String.format(MESSAGE_DELETE_NOTE_SUCCESS, noteToDelete));
47+
}
48+
49+
@Override
50+
public boolean equals(Object other) {
51+
return other == this // short circuit if same object
52+
|| (other instanceof seedu.address.logic.commands.notes.DeleteNoteCommand // instanceof handles nulls
53+
&& targetIndex.equals(((seedu.address.logic.commands.notes.DeleteNoteCommand) other).targetIndex)); // state check
54+
}
55+
}
56+

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import seedu.address.logic.commands.ListAllCommand;
1515
import seedu.address.logic.commands.meetings.*;
1616
import seedu.address.logic.commands.notes.AddNoteCommand;
17+
import seedu.address.logic.commands.notes.DeleteNoteCommand;
1718
import seedu.address.logic.commands.persons.AddPersonCommand;
1819
import seedu.address.logic.commands.persons.ClearPersonCommand;
1920
import seedu.address.logic.commands.persons.DeletePersonCommand;
@@ -29,6 +30,7 @@
2930
import seedu.address.logic.parser.exceptions.ParseException;
3031
import seedu.address.logic.parser.meetings.*;
3132
import seedu.address.logic.parser.notes.AddNoteCommandParser;
33+
import seedu.address.logic.parser.notes.DeleteNoteCommandParser;
3234
import seedu.address.logic.parser.persons.AddPersonCommandParser;
3335
import seedu.address.logic.parser.persons.DeletePersonCommandParser;
3436
import seedu.address.logic.parser.persons.EditPersonCommandParser;
@@ -114,6 +116,9 @@ public Command parseCommand(String userInput) throws ParseException {
114116
case AddNoteCommand.COMMAND_WORD:
115117
return new AddNoteCommandParser().parse(arguments);
116118

119+
case DeleteNoteCommand.COMMAND_WORD:
120+
return new DeleteNoteCommandParser().parse(arguments);
121+
117122
//======================= Timetable =====================================
118123

119124
case SetTimetableCommand.COMMAND_WORD:
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package seedu.address.logic.parser.notes;
2+
3+
import static seedu.address.commons.core.Messages.MESSAGE_INVALID_COMMAND_FORMAT;
4+
5+
import seedu.address.commons.core.index.Index;
6+
import seedu.address.logic.commands.notes.DeleteNoteCommand;
7+
import seedu.address.logic.parser.Parser;
8+
import seedu.address.logic.parser.ParserUtil;
9+
import seedu.address.logic.parser.exceptions.ParseException;
10+
11+
/**
12+
* Parses input arguments and creates a new DeleteNoteCommand object
13+
*/
14+
public class DeleteNoteCommandParser implements Parser<DeleteNoteCommand> {
15+
16+
/**
17+
* Parses the given {@code String} of arguments in the context of the DeleteNoteCommand
18+
* and returns a DeleteNoteCommand object for execution.
19+
* @throws ParseException if the user input does not conform the expected format
20+
*/
21+
public DeleteNoteCommand parse(String args) throws ParseException {
22+
try {
23+
Index index = ParserUtil.parseIndex(args);
24+
return new DeleteNoteCommand(index);
25+
} catch (ParseException pe) {
26+
throw new ParseException(
27+
String.format(MESSAGE_INVALID_COMMAND_FORMAT, DeleteNoteCommand.MESSAGE_USAGE), pe);
28+
}
29+
}
30+
31+
}

0 commit comments

Comments
 (0)