Skip to content

Commit 1ad0673

Browse files
committed
Remove Optional.of() with regards to new overloading constructor
1 parent 35ec63c commit 1ad0673

6 files changed

Lines changed: 22 additions & 62 deletions

File tree

src/main/java/seedu/address/logic/commands/meeting/EditCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ private static Meeting createEditedMeeting(Meeting meetingToEdit, EditMeetingDes
9494
// String updatedLocation = editMeetingDescriptor.getLocation().orElse(meetingToEdit.getLocation());
9595

9696
// return new Meeting(updatedTitle, updatedDesc, updatedFrom, updatedTo, updatedContacts, updatedLocation);
97-
return new Meeting(new Title("A"), new OptionalDescription(Optional.of("B")), new From("2"),
98-
new To("3"), new Contacts(Optional.of("1,2,3")), new Location(Optional.of("SG")));
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"));
9999
}
100100

101101
@Override

src/main/java/seedu/address/logic/parser/meeting/AddCommandParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import seedu.address.logic.parser.Parser;
1717
import seedu.address.logic.parser.Prefix;
1818
import seedu.address.logic.parser.exceptions.ParseException;
19+
import seedu.address.logic.parser.util.ParserCommon;
1920
import seedu.address.model.meeting.meeting.From;
2021
import seedu.address.model.meeting.meeting.Location;
2122
import seedu.address.model.meeting.meeting.Meeting;
@@ -44,11 +45,11 @@ public AddCommand parse(String args) throws ParseException {
4445
}
4546

4647
Title title = ParserUtil.parseTitle(argMultimap.getValue(PREFIX_TITLE).get());
47-
OptionalDescription description = ParserUtil.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION));
48+
OptionalDescription description = ParserCommon.parseDescription(argMultimap.getValue(PREFIX_DESCRIPTION));
4849
From from = ParserUtil.parseFrom(argMultimap.getValue(PREFIX_FROM).get());
4950
To to = ParserUtil.parseTo(argMultimap.getValue(PREFIX_TO).get());
5051
Location location = ParserUtil.parseLocation(argMultimap.getValue(PREFIX_LOCATION));
51-
Contacts contacts = ParserUtil.parseContacts(argMultimap.getValue(PREFIX_CONTACTS));
52+
Contacts contacts = ParserCommon.parseContacts(argMultimap.getValue(PREFIX_CONTACTS));
5253
Meeting meeting = new Meeting(title, description, from, to, contacts, location);
5354

5455
return new AddCommand(meeting);

src/main/java/seedu/address/logic/parser/meeting/ParserUtil.java

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import seedu.address.model.meeting.meeting.From;
1111
import seedu.address.model.meeting.meeting.Location;
1212
import seedu.address.model.meeting.meeting.To;
13-
import seedu.address.model.util.Contacts;
14-
import seedu.address.model.util.OptionalDescription;
1513
import seedu.address.model.util.Title;
1614

1715
/**
@@ -48,23 +46,6 @@ public static Title parseTitle(String title) throws ParseException {
4846
return new Title(trimmedTitle);
4947
}
5048

51-
/**
52-
* Parses a {@code String phone} into a {@code Phone}.
53-
* Leading and trailing whitespaces will be trimmed.
54-
*
55-
* @throws ParseException if the given {@code phone} is invalid.
56-
*/
57-
public static OptionalDescription parseDescription(Optional<String> description) throws ParseException {
58-
if (description.isEmpty()) {
59-
return new OptionalDescription(description);
60-
}
61-
String trimmedDescription = description.get().trim();
62-
if (!OptionalDescription.isValidDescription(trimmedDescription)) {
63-
throw new ParseException(Title.MESSAGE_CONSTRAINTS);
64-
}
65-
return new OptionalDescription(Optional.ofNullable(trimmedDescription));
66-
}
67-
6849
/**
6950
* Parses a {@code String address} into an {@code Address}.
7051
* Leading and trailing whitespaces will be trimmed.
@@ -95,23 +76,6 @@ public static From parseFrom(String from) throws ParseException {
9576
return new From(trimmedFrom);
9677
}
9778

98-
/**
99-
* Parses a {@code String address} into an {@code Address}.
100-
* Leading and trailing whitespaces will be trimmed.
101-
*
102-
* @throws ParseException if the given {@code address} is invalid.
103-
*/
104-
public static Contacts parseContacts(Optional<String> contacts) throws ParseException {
105-
if (contacts.isEmpty()) {
106-
return new Contacts(contacts);
107-
}
108-
String trimmedContacts = contacts.get().trim();
109-
if (!Contacts.isValidContacts(trimmedContacts)) {
110-
throw new ParseException(Contacts.MESSAGE_CONSTRAINTS);
111-
}
112-
return new Contacts(Optional.ofNullable(trimmedContacts));
113-
}
114-
11579
/**
11680
* Parses a {@code String address} into an {@code Address}.
11781
* Leading and trailing whitespaces will be trimmed.
@@ -126,6 +90,6 @@ public static Location parseLocation(Optional<String> location) throws ParseExce
12690
if (!Location.isValidLocation(trimmedLocation)) {
12791
throw new ParseException(Location.MESSAGE_CONSTRAINTS);
12892
}
129-
return new Location(Optional.ofNullable(trimmedLocation));
93+
return new Location(trimmedLocation);
13094
}
13195
}

src/main/java/seedu/address/logic/parser/util/ParserUtil.java renamed to src/main/java/seedu/address/logic/parser/util/ParserCommon.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* Contains utility methods used for parsing strings in the various *Parser classes.
1212
*/
13-
public class ParserUtil {
13+
public class ParserCommon {
1414

1515
/**
1616
* Parses a {@code Optional<String> description} into a {@code Description}.
@@ -26,7 +26,7 @@ public static OptionalDescription parseDescription(Optional<String> description)
2626
if (!OptionalDescription.isValidDescription(trimmedDescription)) {
2727
throw new ParseException(Title.MESSAGE_CONSTRAINTS);
2828
}
29-
return new OptionalDescription(Optional.ofNullable(trimmedDescription));
29+
return new OptionalDescription(trimmedDescription);
3030
}
3131

3232
/**
@@ -43,6 +43,6 @@ public static Contacts parseContacts(Optional<String> contacts) throws ParseExce
4343
if (!Contacts.isValidContacts(trimmedContacts)) {
4444
throw new ParseException(Contacts.MESSAGE_CONSTRAINTS);
4545
}
46-
return new Contacts(Optional.ofNullable(trimmedContacts));
46+
return new Contacts(trimmedContacts);
4747
}
4848
}

src/main/java/seedu/address/model/util/SampleDataUtil.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package seedu.address.model.util;
22

33
import java.util.Arrays;
4-
import java.util.Optional;
54
import java.util.Set;
65
import java.util.stream.Collectors;
76

@@ -65,16 +64,16 @@ public static Deliverable[] getSampleDeliverables() {
6564

6665
public static Meeting[] getSampleMeetings() {
6766
return new Meeting[] {
68-
new Meeting(new Title("Meeting 1"), new OptionalDescription(Optional.of("With business associates")),
67+
new Meeting(new Title("Meeting 1"), new OptionalDescription("With business associates"),
6968
new From("01-01-2020 12:00"),
7069
new To("01-01-2020 14:00"),
71-
new Contacts(Optional.of("1,2,3")),
72-
new Location(Optional.of("Singapore"))),
73-
new Meeting(new Title("Meeting 2"), new OptionalDescription(Optional.of("With product designers")),
70+
new Contacts("1,2,3"),
71+
new Location("Singapore")),
72+
new Meeting(new Title("Meeting 2"), new OptionalDescription("With product designers"),
7473
new From("02-01-2020 12:00"),
7574
new To("02-01-2020 14:00"),
76-
new Contacts(Optional.of("4,5,6")),
77-
new Location(Optional.of("Jakarta")))
75+
new Contacts("4,5,6"),
76+
new Location("Jakarta"))
7877
};
7978
}
8079

src/test/java/seedu/address/testutil/MeetingBuilder.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package seedu.address.testutil;
22

3-
import java.util.Optional;
4-
53
import seedu.address.model.meeting.meeting.From;
64
import seedu.address.model.meeting.meeting.Location;
75
import seedu.address.model.meeting.meeting.Meeting;
@@ -10,17 +8,15 @@
108
import seedu.address.model.util.OptionalDescription;
119
import seedu.address.model.util.Title;
1210

13-
14-
1511
public class MeetingBuilder {
1612

1713
public static final String DEFAULT_TITLE = "Test";
18-
public static final Optional<String> DEFAULT_DESCRIPTION = Optional.of("Refine functional requirements"
19-
+ "with business associates");
14+
public static final String DEFAULT_DESCRIPTION = "Refine functional requirements"
15+
+ "with business associates";
2016
public static final String DEFAULT_FROM = "12-12-2020 08:00";
2117
public static final String DEFAULT_TO = "12-12-2020 09:00";
22-
public static final Optional<String> DEFAULT_CONTACTS = Optional.of("3,6,9");
23-
public static final Optional<String> DEFAULT_LOCATION = Optional.of("Singapore");
18+
public static final String DEFAULT_CONTACTS = "3,6,9";
19+
public static final String DEFAULT_LOCATION = "Singapore";
2420

2521
private Title title;
2622
private OptionalDescription description;
@@ -67,7 +63,7 @@ public MeetingBuilder withTitle(String title) {
6763
* Sets the {@code Description} of the {@code Meeting} that we are building.
6864
*/
6965
public MeetingBuilder withDescription(String description) {
70-
this.description = new OptionalDescription(Optional.ofNullable(description));
66+
this.description = new OptionalDescription(description);
7167
return this;
7268
}
7369

@@ -91,15 +87,15 @@ public MeetingBuilder withTo(String to) {
9187
* Sets the {@code Contacts} of the {@code Meeting} that we are building.
9288
*/
9389
public MeetingBuilder withContacts(String contacts) {
94-
this.contacts = new Contacts(Optional.ofNullable(contacts));
90+
this.contacts = new Contacts(contacts);
9591
return this;
9692
}
9793

9894
/**
9995
* Sets the {@code Location} of the {@code Meeting} that we are building.
10096
*/
10197
public MeetingBuilder withLocation(String location) {
102-
this.location = new Location(Optional.ofNullable(location));
98+
this.location = new Location(location);
10399
return this;
104100
}
105101

0 commit comments

Comments
 (0)