Skip to content

Commit 0be8caf

Browse files
authored
Merge pull request nus-cs2103-AY2021S1#86 from gloon99/branch-Add-Meeting
Add Meeting class
2 parents 0e1846b + 8b7bf3e commit 0be8caf

File tree

14 files changed

+549
-5
lines changed

14 files changed

+549
-5
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package seedu.address.logic.commands;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME;
5+
import static seedu.address.logic.parser.CliSyntax.PREFIX_DATE;
6+
import static seedu.address.logic.parser.CliSyntax.PREFIX_TIME;
7+
import static seedu.address.logic.parser.CliSyntax.PREFIX_CONTACTADD;
8+
9+
import seedu.address.logic.commands.exceptions.CommandException;
10+
import seedu.address.model.Model;
11+
import seedu.address.model.meeting.Meeting;
12+
13+
/**
14+
* Adds a person to the address book.
15+
*/
16+
public class AddMeetingCommand extends Command {
17+
18+
public static final String COMMAND_WORD = "meeting add";
19+
20+
public static final String MESSAGE_USAGE = COMMAND_WORD + ": Adds a person to the address book. "
21+
+ "Parameters: "
22+
+ PREFIX_NAME + "MEETING NAME "
23+
+ PREFIX_DATE + "DATE "
24+
+ PREFIX_TIME + "TIME "
25+
+ "[" + PREFIX_CONTACTADD + "PERSON]...\n"
26+
+ "Example: " + COMMAND_WORD + " "
27+
+ PREFIX_NAME + "CS2103 weekly meeting "
28+
+ PREFIX_DATE + "2020-09-20 "
29+
+ PREFIX_TIME+ "10:00 "
30+
+ PREFIX_CONTACTADD + "Roy "
31+
+ PREFIX_CONTACTADD + "Jerryl ";
32+
33+
public static final String MESSAGE_SUCCESS = "New person added: %1$s";
34+
public static final String MESSAGE_DUPLICATE_MEETING = "This meeting already exists in the address book";
35+
36+
private final Meeting toAdd;
37+
38+
/**
39+
* Creates an AddCommand to add the specified {@code Person}
40+
*/
41+
public AddMeetingCommand(Meeting meeting) {
42+
requireNonNull(meeting);
43+
toAdd = meeting;
44+
}
45+
46+
@Override
47+
public CommandResult execute(Model model) throws CommandException {
48+
requireNonNull(model);
49+
50+
if (model.hasMeeting(toAdd)) {
51+
throw new CommandException(MESSAGE_DUPLICATE_MEETING);
52+
}
53+
54+
model.addMeeting(toAdd);
55+
return new CommandResult(String.format(MESSAGE_SUCCESS, toAdd));
56+
}
57+
58+
@Override
59+
public boolean equals(Object other) {
60+
return other == this // short circuit if same object
61+
|| (other instanceof AddMeetingCommand // instanceof handles nulls
62+
&& toAdd.equals(((AddMeetingCommand) other).toAdd));
63+
}
64+
}
65+

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,7 @@ public class CliSyntax {
1111
public static final Prefix PREFIX_EMAIL = new Prefix("e/");
1212
public static final Prefix PREFIX_TAG = new Prefix("t/");
1313

14+
public static final Prefix PREFIX_DATE = new Prefix("d/");
15+
public static final Prefix PREFIX_TIME = new Prefix("t/");
16+
public static final Prefix PREFIX_CONTACTADD = new Prefix("cA/");
1417
}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package seedu.address.model;
2+
3+
import javafx.collections.ObservableList;
4+
import seedu.address.model.meeting.Meeting;
5+
import seedu.address.model.meeting.UniqueMeetingList;
6+
7+
import java.util.List;
8+
9+
import static java.util.Objects.requireNonNull;
10+
11+
public class MeetingBook implements ReadOnlyMeetingBook{
12+
13+
private final UniqueMeetingList meetings;
14+
15+
/*
16+
* The 'unusual' code block below is a non-static initialization block, sometimes used to avoid duplication
17+
* between constructors. See https://docs.oracle.com/javase/tutorial/java/javaOO/initial.html
18+
*
19+
* Note that non-static init blocks are not recommended to use. There are other ways to avoid duplication
20+
* among constructors.
21+
*/
22+
{
23+
meetings = new UniqueMeetingList();
24+
}
25+
26+
public MeetingBook() {}
27+
28+
public MeetingBook(ReadOnlyMeetingBook toBeCopied) {
29+
this();
30+
resetData(toBeCopied);
31+
}
32+
33+
//// list overwrite operations
34+
public void setMeetings(List<Meeting> meetings) {
35+
this.meetings.setMeetings(meetings);
36+
}
37+
38+
public void resetData(ReadOnlyMeetingBook newData) {
39+
requireNonNull(newData);
40+
setMeetings(newData.getMeetingList());
41+
}
42+
43+
//// meeting-level operations
44+
public boolean hasMeeting(Meeting meeting) {
45+
requireNonNull(meeting);
46+
return meetings.contains(meeting);
47+
}
48+
49+
public void addMeeting(Meeting m) {
50+
meetings.add(m);
51+
}
52+
53+
public void setMeeting(Meeting target, Meeting editedMeeting) {
54+
requireNonNull(editedMeeting);
55+
56+
meetings.setMeeting(target, editedMeeting);
57+
}
58+
59+
public void removeMeeting(Meeting key) {
60+
meetings.remove(key);
61+
}
62+
63+
//// util methods
64+
@Override
65+
public String toString() {
66+
return meetings.asUnmodifiableObservableList().size() + " meetings";
67+
// TODO: refine later
68+
}
69+
70+
@Override
71+
public ObservableList<Meeting> getMeetingList() {
72+
return meetings.asUnmodifiableObservableList();
73+
}
74+
75+
@Override
76+
public boolean equals(Object other) {
77+
return other == this // short circuit if same object
78+
|| (other instanceof MeetingBook // instanceof handles nulls
79+
&& meetings.equals(((MeetingBook) other).meetings));
80+
}
81+
82+
@Override
83+
public int hashCode() {
84+
return meetings.hashCode();
85+
}
86+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import javafx.collections.ObservableList;
77
import seedu.address.commons.core.GuiSettings;
8+
import seedu.address.model.meeting.Meeting;
89
import seedu.address.model.person.Name;
910
import seedu.address.model.person.Person;
1011

@@ -90,4 +91,8 @@ public interface Model {
9091
* @throws NullPointerException if {@code predicate} is null.
9192
*/
9293
void updateFilteredPersonList(Predicate<Person> predicate);
94+
95+
boolean hasMeeting(Meeting meeting);
96+
97+
void addMeeting(Meeting meeting);
9398
}

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import javafx.collections.transformation.FilteredList;
1212
import seedu.address.commons.core.GuiSettings;
1313
import seedu.address.commons.core.LogsCenter;
14+
import seedu.address.model.meeting.Meeting;
1415
import seedu.address.model.person.Name;
1516
import seedu.address.model.person.Person;
1617

@@ -21,25 +22,29 @@ public class ModelManager implements Model {
2122
private static final Logger logger = LogsCenter.getLogger(ModelManager.class);
2223

2324
private final AddressBook addressBook;
25+
private final MeetingBook meetingBook;
2426
private final UserPrefs userPrefs;
2527
private final FilteredList<Person> filteredPersons;
2628

2729
/**
2830
* Initializes a ModelManager with the given addressBook and userPrefs.
2931
*/
30-
public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyUserPrefs userPrefs) {
32+
public ModelManager(ReadOnlyAddressBook addressBook, ReadOnlyMeetingBook meetingBook, ReadOnlyUserPrefs userPrefs) {
3133
super();
32-
requireAllNonNull(addressBook, userPrefs);
34+
requireAllNonNull(addressBook, meetingBook, userPrefs);
3335

34-
logger.fine("Initializing with address book: " + addressBook + " and user prefs " + userPrefs);
36+
logger.fine("Initializing with address book: " + addressBook
37+
+ " and meetingBook " + meetingBook
38+
+ " and user prefs " + userPrefs);
3539

3640
this.addressBook = new AddressBook(addressBook);
41+
this.meetingBook = new MeetingBook(meetingBook);
3742
this.userPrefs = new UserPrefs(userPrefs);
3843
filteredPersons = new FilteredList<>(this.addressBook.getPersonList());
3944
}
4045

4146
public ModelManager() {
42-
this(new AddressBook(), new UserPrefs());
47+
this(new AddressBook(), new MeetingBook(), new UserPrefs());
4348
}
4449

4550
//=========== UserPrefs ==================================================================================
@@ -119,6 +124,19 @@ public void setPerson(Person target, Person editedPerson) {
119124
addressBook.setPerson(target, editedPerson);
120125
}
121126

127+
//=========== Meetings ===================================================================================
128+
@Override
129+
public boolean hasMeeting(Meeting meeting) {
130+
requireNonNull(meeting);
131+
return meetingBook.hasMeeting(meeting);
132+
};
133+
134+
@Override
135+
public void addMeeting(Meeting meeting) {
136+
meetingBook.addMeeting(meeting);
137+
updateFilteredPersonList(PREDICATE_SHOW_ALL_PERSONS);
138+
};
139+
122140
//=========== Filtered Person List Accessors =============================================================
123141

124142
/**
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package seedu.address.model;
2+
3+
import javafx.collections.ObservableList;
4+
import seedu.address.model.meeting.Meeting;
5+
6+
public interface ReadOnlyMeetingBook {
7+
8+
/**
9+
* Returns an unmodifiable view of the persons list.
10+
* This list will not contain any duplicate persons.
11+
*/
12+
ObservableList<Meeting> getMeetingList();
13+
}
14+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package seedu.address.model.meeting;
2+
3+
import static java.util.Objects.requireNonNull;
4+
import static seedu.address.commons.util.AppUtil.checkArgument;
5+
6+
public class Date {
7+
public static final String MESSAGE_CONSTRAINTS =
8+
"Dates should be in the format yyyy-mm-dd";
9+
public static final String VALIDATION_REGEX = "\\d{3,}";
10+
public final String value;
11+
12+
/**
13+
* Constructs a {@code Date}.
14+
*
15+
* @param date A valid date.
16+
*/
17+
public Date(String date) {
18+
requireNonNull(date);
19+
checkArgument(isValidDate(date), MESSAGE_CONSTRAINTS);
20+
value = date;
21+
}
22+
23+
/**
24+
* Returns true if a given string is a valid phone number.
25+
*/
26+
public static boolean isValidDate(String test) {
27+
return test.length() == 10
28+
&& test.charAt(4) == '-'
29+
&& test.charAt(7) == '-';
30+
//todo: check if date exists
31+
}
32+
33+
@Override
34+
public String toString() {
35+
return value;
36+
}
37+
38+
@Override
39+
public boolean equals(Object other) {
40+
return other == this // short circuit if same object
41+
|| (other instanceof Date // instanceof handles nulls
42+
&& value.equals(((Date) other).value)); // state check
43+
}
44+
45+
@Override
46+
public int hashCode() {
47+
return value.hashCode();
48+
}
49+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package seedu.address.model.meeting;
2+
3+
import seedu.address.model.person.Person;
4+
5+
import java.util.Collections;
6+
import java.util.HashSet;
7+
import java.util.Objects;
8+
import java.util.Set;
9+
10+
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
11+
12+
public class Meeting {
13+
// Identity fields
14+
private final MeetingName name;
15+
private final Date date;
16+
private final Time time;
17+
18+
// Data fields
19+
private final Set<Person> persons = new HashSet<>();
20+
21+
public Meeting(MeetingName name, Date date, Time time, Set<Person> persons) {
22+
requireAllNonNull(name, date, time, persons);
23+
this.name = name;
24+
this.date = date;
25+
this.time = time;
26+
this.persons.addAll(persons);
27+
}
28+
29+
public MeetingName getName(){
30+
return this.name;
31+
}
32+
33+
public Date getDate(){
34+
return this.date;
35+
}
36+
37+
public Time getTime(){
38+
return this.time;
39+
}
40+
41+
public Set<Person> getPersons() {
42+
return Collections.unmodifiableSet(persons);
43+
}
44+
45+
public boolean isSameMeeting(Meeting otherMeeting) {
46+
if (otherMeeting == this) {
47+
return true;
48+
}
49+
50+
return otherMeeting != null
51+
&& otherMeeting.getName().equals(getName())
52+
&& otherMeeting.getDate().equals(getDate())
53+
&& otherMeeting.getTime().equals(getTime());
54+
}
55+
56+
@Override
57+
public boolean equals(Object other) {
58+
if (other == this) {
59+
return true;
60+
}
61+
62+
if (!(other instanceof Meeting)) {
63+
return false;
64+
}
65+
66+
Meeting otherMeeting = (Meeting) other;
67+
return otherMeeting.getName().equals(getName())
68+
&& otherMeeting.getDate().equals(getDate())
69+
&& otherMeeting.getTime().equals(getTime());
70+
}
71+
72+
@Override
73+
public int hashCode() {
74+
// use this method for custom fields hashing instead of implementing your own
75+
return Objects.hash(name, date, time, persons);
76+
}
77+
78+
@Override
79+
public String toString() {
80+
final StringBuilder builder = new StringBuilder();
81+
builder.append(getName())
82+
.append(" Date: ")
83+
.append(getDate())
84+
.append(" Time: ")
85+
.append(getTime())
86+
.append(" Persons: ");
87+
getPersons().forEach(builder::append);
88+
return builder.toString();
89+
}
90+
}

0 commit comments

Comments
 (0)