forked from nus-cs2103-AY2021S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2103-AY2021S1#70 from claraadora/meeting-fix
Convert to Optionals for Optional fields
- Loading branch information
Showing
16 changed files
with
226 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/seedu/address/logic/parser/util/ParserCommon.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package seedu.address.logic.parser.util; | ||
|
||
import java.util.Optional; | ||
|
||
import seedu.address.logic.parser.exceptions.ParseException; | ||
import seedu.address.model.util.Contacts; | ||
import seedu.address.model.util.OptionalDescription; | ||
import seedu.address.model.util.Title; | ||
|
||
/** | ||
* Contains utility methods used for parsing strings in the various *Parser classes. | ||
*/ | ||
public class ParserCommon { | ||
|
||
/** | ||
* Parses a {@code Optional<String> description} into a {@code Description}. | ||
* Leading and trailing whitespaces will be trimmed. | ||
* | ||
* @throws ParseException if the given {@code phone} is invalid. | ||
*/ | ||
public static OptionalDescription parseDescription(Optional<String> description) throws ParseException { | ||
if (description.isEmpty()) { | ||
return new OptionalDescription(description); | ||
} | ||
String trimmedDescription = description.get().trim(); | ||
if (!OptionalDescription.isValidDescription(trimmedDescription)) { | ||
throw new ParseException(Title.MESSAGE_CONSTRAINTS); | ||
} | ||
return new OptionalDescription(trimmedDescription); | ||
} | ||
|
||
/** | ||
* Parses a {@code Optional<String> contacts} into an {@code Contacts}. | ||
* Leading and trailing whitespaces will be trimmed. | ||
* | ||
* @throws ParseException if the given {@code contacts} is invalid. | ||
*/ | ||
public static Contacts parseContacts(Optional<String> contacts) throws ParseException { | ||
if (contacts.isEmpty()) { | ||
return new Contacts(contacts); | ||
} | ||
String trimmedContacts = contacts.get().trim(); | ||
if (!Contacts.isValidContacts(trimmedContacts)) { | ||
throw new ParseException(Contacts.MESSAGE_CONSTRAINTS); | ||
} | ||
return new Contacts(trimmedContacts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.