11package seedu .address .logic .commands .meeting ;
22
33import static java .util .Objects .requireNonNull ;
4- //import static seedu.address.logic.parser.meeting.CliSyntax.PREFIX_TITLE;
5- //import static seedu.address.logic.parser.meeting.CliSyntax.PREFIX_DESCRIPTION;
6- //import static seedu.address.logic.parser.meeting.CliSyntax.PREFIX_FROM;
7- //import static seedu.address.logic.parser.meeting.CliSyntax.PREFIX_FROM;
8- //import static seedu.address.logic.parser.meeting.CliSyntax.PREFIX_TO;
9- //import static seedu.address.logic.parser.meeting.CliSyntax.PREFIX_CONTACTS;
10-
11- //import java.util.Collections;
12- //import java.util.HashSet;
13- import java .util .ArrayList ;
4+ import static seedu .address .logic .parser .meeting .CliSyntax .PREFIX_CONTACTS ;
5+ import static seedu .address .logic .parser .meeting .CliSyntax .PREFIX_DESCRIPTION ;
6+ import static seedu .address .logic .parser .meeting .CliSyntax .PREFIX_FROM ;
7+ import static seedu .address .logic .parser .meeting .CliSyntax .PREFIX_LOCATION ;
8+ import static seedu .address .logic .parser .meeting .CliSyntax .PREFIX_TITLE ;
9+ import static seedu .address .logic .parser .meeting .CliSyntax .PREFIX_TO ;
10+ import static seedu .address .model .meeting .ModelMeeting .PREDICATE_SHOW_ALL_MEETINGS ;
11+
1412import java .util .List ;
1513import java .util .Optional ;
16- //import java.util.Set;
1714
1815import seedu .address .commons .core .index .Index ;
1916import seedu .address .commons .util .CollectionUtil ;
3229public class EditCommand extends Command {
3330
3431 public static final String COMMAND_WORD = "edit" ;
35- public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the meeting." ;
36-
37-
38- public static final String MESSAGE_EDIT_MEETING_SUCCESS = "Edited Person: %1$s" ;
32+ public static final String MESSAGE_USAGE = COMMAND_WORD + ": Edits the details of the meeting identified "
33+ + "by the index number used in the displayed meeting list. "
34+ + "Existing values will be overwritten by the input values.\n "
35+ + "Parameters: INDEX (must be a positive integer) "
36+ + "[" + PREFIX_TITLE + "TITLE] "
37+ + "[" + PREFIX_DESCRIPTION + "DESCRIPTION] "
38+ + "[" + PREFIX_FROM + "FROM] "
39+ + "[" + PREFIX_TO + "TO] "
40+ + "[" + PREFIX_CONTACTS + "CONTACTS] "
41+ + "[" + PREFIX_LOCATION + "LOCATION] "
42+ + "Example: " + COMMAND_WORD + " 1 "
43+ + PREFIX_TITLE + "Discuss ALL features "
44+ + PREFIX_FROM + "2020-12-31 09:00" ;
45+
46+
47+ public static final String MESSAGE_EDIT_MEETING_SUCCESS = "Edited Meeting: %1$s" ;
3948 public static final String MESSAGE_NOT_EDITED = "At least one field to edit must be provided." ;
40- public static final String MESSAGE_DUPLICATE_MEETING = "This person already exists in the address book." ;
49+ public static final String MESSAGE_DUPLICATE_MEETING = "This meeting already exists in the meeting book." ;
4150 public static final String MESSAGE_INVALID_MEETING_DISPLAYED_INDEX = "Invalid Meeting index." ;
4251
4352
4453 private final Index targetIndex ;
4554 private final EditMeetingDescriptor editMeetingDescriptor ;
4655
4756 /**
48- * @param index of the person in the filtered person list to edit
49- * @param editMeetingDescriptor details to edit the person with
57+ * @param index of the meeting in the filtered person list to edit
58+ * @param editMeetingDescriptor details to edit the meeting with
5059 */
5160 public EditCommand (Index index , EditMeetingDescriptor editMeetingDescriptor ) {
5261 requireNonNull (index );
@@ -60,24 +69,20 @@ public EditCommand(Index index, EditMeetingDescriptor editMeetingDescriptor) {
6069 public CommandResult execute (ModelMeeting modelMeeting ) throws CommandException {
6170 requireNonNull (modelMeeting );
6271
63- //TODO: Add getFilteredMeetingList
64- //List<Meeting> lastShownList = modelMeeting.getFilteredMeetingList();
65- List <Meeting > lastShownList = new ArrayList <Meeting >();
72+ List <Meeting > lastShownList = modelMeeting .getFilteredMeetingList ();
6673 if (targetIndex .getZeroBased () >= lastShownList .size ()) {
6774 throw new CommandException (MESSAGE_INVALID_MEETING_DISPLAYED_INDEX );
6875 }
6976
7077 Meeting meetingToEdit = lastShownList .get (targetIndex .getZeroBased ());
7178 Meeting editedMeeting = createEditedMeeting (meetingToEdit , editMeetingDescriptor );
7279
73- //TODO: throw exception if meetingToEdit.isSameMeeting(editedMeeting) makes no changes
74- if (modelMeeting .hasMeeting (editedMeeting )) {
80+ if (!meetingToEdit .isSameMeeting (editedMeeting ) && modelMeeting .hasMeeting (editedMeeting )) {
7581 throw new CommandException (MESSAGE_DUPLICATE_MEETING );
7682 }
7783
78- //TODO: implement setMeeting and updateFilteredMeetingList
79- //modelMeeting.setMeeting(meetingToEdit, editedMeeting);
80- //modelMeeting.updateFilteredMeetingList(PREDICATE_SHOW_ALL_Meeting);
84+ modelMeeting .setMeeting (meetingToEdit , editedMeeting );
85+ modelMeeting .updateFilteredMeetingList (PREDICATE_SHOW_ALL_MEETINGS );
8186
8287
8388 return new CommandResult (String .format (MESSAGE_EDIT_MEETING_SUCCESS , editedMeeting ));
@@ -86,16 +91,22 @@ public CommandResult execute(ModelMeeting modelMeeting) throws CommandException
8691 private static Meeting createEditedMeeting (Meeting meetingToEdit , EditMeetingDescriptor editMeetingDescriptor ) {
8792 assert meetingToEdit != null ;
8893
89- // String updatedTitle = editMeetingDescriptor.getTitle().orElse(meetingToEdit.getTitle());
90- // String updatedDesc = editMeetingDescriptor.getDescription().orElse(meetingToEdit.getDescription());
91- // String updatedFrom = editMeetingDescriptor.getFrom().orElse(meetingToEdit.getFrom());
92- // String updatedTo = editMeetingDescriptor.getTo().orElse(meetingToEdit.getTo());
93- // String updatedContacts = editMeetingDescriptor.getContacts().orElse(meetingToEdit.getContacts());
94- // String updatedLocation = editMeetingDescriptor.getLocation().orElse(meetingToEdit.getLocation());
94+ Title updatedTitle = editMeetingDescriptor .getTitle ().orElse (meetingToEdit .getTitle ());
95+
96+ // Description takes optional String
97+ OptionalDescription updatedDesc = editMeetingDescriptor .getDescription ()
98+ .orElse (meetingToEdit .getDescription ());
99+
100+ From updatedFrom = editMeetingDescriptor .getFrom ().orElse (meetingToEdit .getFrom ());
101+ To updatedTo = editMeetingDescriptor .getTo ().orElse (meetingToEdit .getTo ());
102+
103+ // Contacts takes optional String
104+ Contacts updatedContacts = editMeetingDescriptor .getContacts ().orElse (meetingToEdit .getContacts ());
105+
106+ // Location takes optional String
107+ Location updatedLocation = editMeetingDescriptor .getLocation ().orElse (meetingToEdit .getLocation ());
95108
96- // return new Meeting(updatedTitle, updatedDesc, updatedFrom, updatedTo, updatedContacts, updatedLocation);
97- return new Meeting (new Title ("A" ), new OptionalDescription ("B" ), new From ("2" ),
98- new To ("3" ), new Contacts ("1,2,3" ), new Location ("SG" ));
109+ return new Meeting (updatedTitle , updatedDesc , updatedFrom , updatedTo , updatedContacts , updatedLocation );
99110 }
100111
101112 @ Override
@@ -120,18 +131,19 @@ public boolean equals(Object other) {
120131 *
121132 */
122133 public static class EditMeetingDescriptor {
123- private String title ;
124- private String description ;
125- private String from ;
126- private String to ;
127- private String contacts ;
128- private String location ;
134+ private Title title ;
135+ private OptionalDescription description ;
136+ private From from ;
137+ private To to ;
138+ private Contacts contacts ;
139+ private Location location ;
129140
130141 public EditMeetingDescriptor () {
131142 }
132143
133144 /**
134145 * Copy attributes from meeting to be edited.
146+ *
135147 * @param toCopy meeting to be edited.
136148 */
137149 public EditMeetingDescriptor (EditMeetingDescriptor toCopy ) {
@@ -147,51 +159,51 @@ public boolean isAnyFieldEdited() {
147159 return CollectionUtil .isAnyNonNull (title , description , from , to , contacts , location );
148160 }
149161
150- public void setTitle (String title ) {
162+ public void setTitle (Title title ) {
151163 this .title = title ;
152164 }
153165
154- public Optional <String > getTitle () {
166+ public Optional <Title > getTitle () {
155167 return Optional .ofNullable (this .title );
156168 }
157169
158- public void setDescription (String description ) {
170+ public void setDescription (OptionalDescription description ) {
159171 this .description = description ;
160172 }
161173
162- public Optional <String > getDescription () {
163- return Optional .ofNullable (this . description );
174+ public Optional <OptionalDescription > getDescription () {
175+ return Optional .ofNullable (description );
164176 }
165177
166- public void setFrom (String from ) {
178+ public void setFrom (From from ) {
167179 this .from = from ;
168180 }
169181
170- public Optional <String > getFrom () {
182+ public Optional <From > getFrom () {
171183 return Optional .ofNullable (this .from );
172184 }
173185
174- public void setTo (String to ) {
186+ public void setTo (To to ) {
175187 this .to = to ;
176188 }
177189
178- public Optional <String > getTo () {
190+ public Optional <To > getTo () {
179191 return Optional .ofNullable (this .to );
180192 }
181193
182- public void setContacts (String contact ) {
194+ public void setContacts (Contacts contact ) {
183195 this .contacts = contact ;
184196 }
185197
186- public Optional <String > getContacts () {
198+ public Optional <Contacts > getContacts () {
187199 return Optional .ofNullable (this .contacts );
188200 }
189201
190- public void setLocation (String location ) {
202+ public void setLocation (Location location ) {
191203 this .location = location ;
192204 }
193205
194- public Optional <String > getLocation () {
206+ public Optional <Location > getLocation () {
195207 return Optional .ofNullable (this .location );
196208 }
197209
0 commit comments