Skip to content

Commit 39b2f7f

Browse files
committed
Updates Model to incorporate Note
1 parent 75b31ce commit 39b2f7f

5 files changed

Lines changed: 210 additions & 5 deletions

File tree

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,51 @@
11
package seedu.address.logic.commands.notes;
22

3+
import static java.util.Objects.requireNonNull;
34
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
45

5-
public class AddNoteCommand {
6+
import seedu.address.logic.commands.Command;
7+
import seedu.address.logic.commands.CommandResult;
8+
import seedu.address.logic.commands.exceptions.CommandException;
9+
import seedu.address.model.Model;
10+
import seedu.address.model.note.Note;
11+
12+
public class AddNoteCommand extends Command {
613

714
public static final String COMMAND_WORD = "addn";
815

916
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a note to the note book. "
1017
+ "Parameters: "
1118
+ PREFIX_NAME + "NAME ";
1219

20+
public static final String MESSAGE_SUCCESS = "New note added: %1$s";
21+
public static final String MESSAGE_DUPLICATE_NOTE = "This note already exists in the note book";
22+
23+
private final Note toAdd;
24+
25+
/**
26+
* Creates an AddNoteCommand to add the specified {@code Note}
27+
*/
28+
public AddNoteCommand(Note note) {
29+
requireNonNull(note);
30+
this.toAdd = note;
31+
}
32+
33+
@Override
34+
public CommandResult execute(Model model) throws CommandException {
35+
requireNonNull(model);
36+
37+
if (model.hasNote(toAdd)) {
38+
throw new CommandException(MESSAGE_DUPLICATE_NOTE);
39+
}
40+
41+
model.addNote(toAdd);
42+
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
43+
}
1344

45+
@Override
46+
public boolean equals(Object other) {
47+
return other == this // short circuit if same object
48+
|| (other instanceof AddNoteCommand // instanceof handles nulls
49+
&& toAdd.equals(((AddNoteCommand) other).toAdd));
50+
}
1451
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import seedu.address.logic.commands.HelpCommand;
1414
import seedu.address.logic.commands.ListAllCommand;
1515
import seedu.address.logic.commands.meetings.*;
16+
import seedu.address.logic.commands.notes.AddNoteCommand;
1617
import seedu.address.logic.commands.persons.AddPersonCommand;
1718
import seedu.address.logic.commands.persons.ClearPersonCommand;
1819
import seedu.address.logic.commands.persons.DeletePersonCommand;
@@ -27,6 +28,7 @@
2728
import seedu.address.logic.parser.connections.DeletePersonToMeetingConnectionParser;
2829
import seedu.address.logic.parser.exceptions.ParseException;
2930
import seedu.address.logic.parser.meetings.*;
31+
import seedu.address.logic.parser.notes.AddNoteCommandParser;
3032
import seedu.address.logic.parser.persons.AddPersonCommandParser;
3133
import seedu.address.logic.parser.persons.DeletePersonCommandParser;
3234
import seedu.address.logic.parser.persons.EditPersonCommandParser;

src/main/java/seedu/address/model/Model.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
import seedu.address.model.group.Group;
1717
import seedu.address.model.meeting.Meeting;
1818
import seedu.address.model.meeting.ReadOnlyMeetingBook;
19+
import seedu.address.model.note.Note;
20+
import seedu.address.model.note.ReadOnlyNoteBook;
1921
import seedu.address.model.person.Person;
2022
import seedu.address.model.person.ReadOnlyAddressBook;
2123
import seedu.address.model.reminder.ReadOnlyReminderBook;
@@ -27,6 +29,7 @@ public interface Model {
2729
/** {@code Predicate} that always evaluate to true */
2830
Predicate<Person> PREDICATE_SHOW_ALL_PERSONS = unused -> true;
2931
Predicate<Meeting> PREDICATE_SHOW_ALL_MEETINGS = unused -> true;
32+
Predicate<Note> PREDICATE_SHOW_ALL_NOTES = unused -> true;
3033

3134
/**
3235
* Replaces user prefs data with the data in {@code userPrefs}.
@@ -223,6 +226,50 @@ public interface Model {
223226
*/
224227
ObservableList<Person> getFilteredPersonListByMeetingConnection(Meeting meeting);
225228

229+
// ======================= Note part of the note Model interface ============================ //
230+
231+
/**
232+
* Replaces note book data with the data in {@code noteBook}.
233+
*/
234+
void setNoteBook(ReadOnlyNoteBook noteBook);
235+
236+
/** Returns the NoteBook */
237+
ReadOnlyNoteBook getNoteBook();
238+
239+
/**
240+
* Returns true if a note with the same content as {@code note} exists in the note book.
241+
*/
242+
boolean hasNote(Note note);
243+
244+
245+
/**
246+
* Deletes the given note.
247+
* The note must exist in the note book.
248+
*/
249+
void deleteNote(Note target);
250+
251+
/**
252+
* Adds the given note.
253+
* {@code note} must not already exist in the note book.
254+
*/
255+
void addNote(Note note);
256+
257+
/**
258+
* Replaces the given note {@code target} with {@code editedNote}.
259+
* {@code target} must exist in the note book.
260+
* The content of {@code editedNote} must not be the same as another existing note in the note book.
261+
*/
262+
void setNote(Note target, Note editedNote);
263+
264+
/** Returns an unmodifiable view of the filtered note list */
265+
ObservableList<Note> getFilteredNoteList();
266+
267+
/**
268+
* Updates the filter of the filtered note list to filter by the given {@code predicate}.
269+
* @throws NullPointerException if {@code predicate} is null.
270+
*/
271+
void updateFilteredNoteList(Predicate<Note> predicate);
272+
226273

227274
//============================= Timetable settings =====================================
228275

src/main/java/seedu/address/model/ModelManager.java

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import seedu.address.model.meeting.MeetingBook;
2727
import seedu.address.model.meeting.ReadOnlyMeetingBook;
2828
import seedu.address.model.meeting.UniqueMeetingList;
29+
import seedu.address.model.note.Note;
30+
import seedu.address.model.note.NoteBook;
31+
import seedu.address.model.note.ReadOnlyNoteBook;
2932
import seedu.address.model.person.AddressBook;
3033
import seedu.address.model.person.Person;
3134
import seedu.address.model.person.ReadOnlyAddressBook;
@@ -56,6 +59,10 @@ public class ModelManager implements Model {
5659

5760
private final ReminderBook reminderBook;
5861

62+
//=============== Note ===========================================================
63+
private final NoteBook noteBook;
64+
private final FilteredList<Note> filteredNotes;
65+
5966
//=============== Timetable ===========================================================
6067
private final TimetablePrefs timetablePrefs;
6168

@@ -80,6 +87,10 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs
8087
this.connection = new PersonMeetingConnection();
8188
this.reminderBook = new ReminderBook(this.meetingBook);
8289

90+
//================== Timetable ==================================================================
91+
this.noteBook = new NoteBook();
92+
this.filteredNotes = new FilteredList<>(this.noteBook.getNoteList());
93+
8394
//================== Timetable ==================================================================
8495
//default initializes to current localdate
8596
timetablePrefs = new TimetablePrefs(LocalDate.now());
@@ -89,7 +100,7 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs
89100
* Initializes a ModelManager with the given addressBook, meetingBOok and userPrefs
90101
*/
91102
public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyMeetingBook meetingBook,
92-
ReadOnlyUserPrefs userPrefs) {
103+
ReadOnlyNoteBook noteBook, ReadOnlyUserPrefs userPrefs) {
93104
super();
94105
requireAllNonNull(addressBook, userPrefs);
95106

@@ -107,6 +118,10 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyMeetingBook meeting
107118
this.connection = new PersonMeetingConnection();
108119
this.reminderBook = new ReminderBook(this.meetingBook);
109120

121+
//================== Note ==================================================================
122+
this.noteBook = new NoteBook(noteBook);
123+
this.filteredNotes = new FilteredList<>(this.noteBook.getNoteList());
124+
110125
//================== Timetable ==================================================================
111126
//default initializes to current localdate
112127
timetablePrefs = new TimetablePrefs(LocalDate.now());
@@ -116,7 +131,8 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyMeetingBook meeting
116131
* Initializes a ModelManager with the given addressBook, meetingBook, userPrefs and PersonMeetingConnection
117132
*/
118133
public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyMeetingBook meetingBook,
119-
ReadOnlyUserPrefs userPrefs, PersonMeetingConnection connection) {
134+
ReadOnlyNoteBook noteBook, ReadOnlyUserPrefs userPrefs,
135+
PersonMeetingConnection connection) {
120136
super();
121137
requireAllNonNull(addressBook, userPrefs);
122138

@@ -133,6 +149,11 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyMeetingBook meeting
133149
// TODO: Modify the signature of ModelManager so that we can add connection inside it.
134150
this.connection = connection;
135151
this.reminderBook = new ReminderBook(this.meetingBook);
152+
153+
//================== Note ==================================================================
154+
this.noteBook = new NoteBook(noteBook);
155+
this.filteredNotes = new FilteredList<>(this.noteBook.getNoteList());
156+
136157
//================== Timetable ==================================================================
137158
//default initializes to current localdate
138159
timetablePrefs = new TimetablePrefs(LocalDate.now());
@@ -141,7 +162,7 @@ public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyMeetingBook meeting
141162

142163

143164
public ModelManager() {
144-
this(new AddressBook(), new MeetingBook(), new UserPrefs());
165+
this(new AddressBook(), new MeetingBook(), new NoteBook(), new UserPrefs());
145166
}
146167

147168
//=========== UserPrefs ==================================================================================
@@ -425,6 +446,57 @@ public void sortFilteredMeetingList(Comparator<Meeting> comparator) {
425446
sortedBeforeFilterMeetings.setComparator(comparator);
426447
}
427448

449+
// ======================= Note part of the note Model interface ============================ //
450+
451+
@Override
452+
public void setNoteBook(ReadOnlyNoteBook noteBook) {
453+
this.noteBook.resetData(noteBook);
454+
}
455+
456+
@Override
457+
public ReadOnlyNoteBook getNoteBook() {
458+
return noteBook;
459+
}
460+
461+
@Override
462+
public boolean hasNote(Note note) {
463+
requireNonNull(note);
464+
return noteBook.hasNote(note);
465+
}
466+
467+
@Override
468+
public void deleteNote(Note target) {
469+
noteBook.removeNote(target);
470+
}
471+
472+
@Override
473+
public void addNote(Note note) {
474+
noteBook.addNote(note);
475+
updateFilteredNoteList(PREDICATE_SHOW_ALL_NOTES);
476+
}
477+
478+
@Override
479+
public void setNote(Note target, Note editedNote) {
480+
requireAllNonNull(target, editedNote);
481+
482+
noteBook.setNote(target, editedNote);
483+
}
484+
485+
/**
486+
* Returns an unmodifiable view of the list of {@code Note} backed by the internal list of
487+
* {@code versionedNoteBook}
488+
*/
489+
@Override
490+
public ObservableList<Note> getFilteredNoteList() {
491+
return filteredNotes;
492+
}
493+
494+
@Override
495+
public void updateFilteredNoteList(Predicate<Note> predicate) {
496+
requireNonNull(predicate);
497+
filteredNotes.setPredicate(predicate);
498+
}
499+
428500
//================= Get timetable prefs methods ================================================
429501

430502
@Override
@@ -457,7 +529,8 @@ public boolean equals(Object obj) {
457529
&& userPrefs.equals(other.userPrefs)
458530
&& filteredPersons.equals(other.filteredPersons)
459531
&& meetingBook.equals(other.meetingBook)
460-
&& filteredMeetings.equals(other.filteredMeetings);
532+
&& filteredMeetings.equals(other.filteredMeetings)
533+
&& noteBook.equals(other.noteBook);
461534
}
462535

463536
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package seedu.address.storage;
2+
3+
import java.io.IOException;
4+
import java.nio.file.Path;
5+
import java.util.Optional;
6+
7+
import seedu.address.commons.exceptions.DataConversionException;
8+
import seedu.address.model.note.NoteBook;
9+
import seedu.address.model.note.ReadOnlyNoteBook;
10+
11+
/**
12+
* Represents a storage for {@link NoteBook}.
13+
*/
14+
public interface NoteBookStorage {
15+
16+
/**
17+
* Returns the file path of the data file.
18+
*/
19+
Path getNoteBookFilePath();
20+
21+
/**
22+
* Returns NoteBook data as a {@link ReadOnlyNoteBook}.
23+
* Returns {@code Optional.empty()} if storage file is not found.
24+
* @throws DataConversionException if the data in storage is not in the expected format.
25+
* @throws IOException if there was any problem when reading from the storage.
26+
*/
27+
Optional<ReadOnlyNoteBook> readNoteBook() throws DataConversionException, IOException;
28+
29+
/**
30+
* @see #getNoteBookFilePath()
31+
*/
32+
Optional<ReadOnlyNoteBook> readNoteBook(Path filePath) throws DataConversionException, IOException;
33+
34+
/**
35+
* Saves the given {@link ReadOnlyNoteBook} to the storage.
36+
* @param noteBook cannot be null.
37+
* @throws IOException if there was any problem writing to the file.
38+
*/
39+
void saveNoteBook(ReadOnlyNoteBook noteBook) throws IOException;
40+
41+
/**
42+
* @see #saveNoteBook(ReadOnlyNoteBook)
43+
*/
44+
void saveNoteBook(ReadOnlyNoteBook noteBook, Path filePath) throws IOException;
45+
46+
}

0 commit comments

Comments
 (0)