Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
Merge d2e3f8d into edc42f0
Browse files Browse the repository at this point in the history
  • Loading branch information
pyokagan committed Dec 5, 2017
2 parents edc42f0 + d2e3f8d commit fd47a3b
Show file tree
Hide file tree
Showing 18 changed files with 445 additions and 151 deletions.
85 changes: 80 additions & 5 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Expand Up @@ -43,13 +43,43 @@ public static Index parseIndex(String oneBasedIndex) throws IllegalValueExceptio
return Index.fromOneBased(Integer.parseInt(trimmedIndex));
}

/**
* Parses a {@code String name} into a {@code Name}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws IllegalValueException if the given {@code name} is invalid.
*/
public static Name parseName(String name) throws IllegalValueException {
requireNonNull(name);
String trimmedName = name.trim();
if (!Name.isValidName(trimmedName)) {
throw new IllegalValueException(Name.MESSAGE_NAME_CONSTRAINTS);
}
return new Name(trimmedName);
}

/**
* Parses a {@code Optional<String> name} into an {@code Optional<Name>} if {@code name} is present.
* See header comment of this class regarding the use of {@code Optional} parameters.
*/
public static Optional<Name> parseName(Optional<String> name) throws IllegalValueException {
requireNonNull(name);
return name.isPresent() ? Optional.of(new Name(name.get())) : Optional.empty();
return name.isPresent() ? Optional.of(parseName(name.get())) : Optional.empty();
}

/**
* Parses a {@code String phone} into a {@code Phone}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws IllegalValueException if the given {@code phone} is invalid.
*/
public static Phone parsePhone(String phone) throws IllegalValueException {
requireNonNull(phone);
String trimmedPhone = phone.trim();
if (!Phone.isValidPhone(trimmedPhone)) {
throw new IllegalValueException(Phone.MESSAGE_PHONE_CONSTRAINTS);
}
return new Phone(trimmedPhone);
}

/**
Expand All @@ -58,7 +88,22 @@ public static Optional<Name> parseName(Optional<String> name) throws IllegalValu
*/
public static Optional<Phone> parsePhone(Optional<String> phone) throws IllegalValueException {
requireNonNull(phone);
return phone.isPresent() ? Optional.of(new Phone(phone.get())) : Optional.empty();
return phone.isPresent() ? Optional.of(parsePhone(phone.get())) : Optional.empty();
}

/**
* Parses a {@code String address} into an {@code Address}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws IllegalValueException if the given {@code address} is invalid.
*/
public static Address parseAddress(String address) throws IllegalValueException {
requireNonNull(address);
String trimmedAddress = address.trim();
if (!Address.isValidAddress(trimmedAddress)) {
throw new IllegalValueException(Address.MESSAGE_ADDRESS_CONSTRAINTS);
}
return new Address(trimmedAddress);
}

/**
Expand All @@ -67,7 +112,22 @@ public static Optional<Phone> parsePhone(Optional<String> phone) throws IllegalV
*/
public static Optional<Address> parseAddress(Optional<String> address) throws IllegalValueException {
requireNonNull(address);
return address.isPresent() ? Optional.of(new Address(address.get())) : Optional.empty();
return address.isPresent() ? Optional.of(parseAddress(address.get())) : Optional.empty();
}

/**
* Parses a {@code String email} into an {@code Email}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws IllegalValueException if the given {@code email} is invalid.
*/
public static Email parseEmail(String email) throws IllegalValueException {
requireNonNull(email);
String trimmedEmail = email.trim();
if (!Email.isValidEmail(trimmedEmail)) {
throw new IllegalValueException(Email.MESSAGE_EMAIL_CONSTRAINTS);
}
return new Email(trimmedEmail);
}

/**
Expand All @@ -76,7 +136,22 @@ public static Optional<Address> parseAddress(Optional<String> address) throws Il
*/
public static Optional<Email> parseEmail(Optional<String> email) throws IllegalValueException {
requireNonNull(email);
return email.isPresent() ? Optional.of(new Email(email.get())) : Optional.empty();
return email.isPresent() ? Optional.of(parseEmail(email.get())) : Optional.empty();
}

/**
* Parses a {@code String tag} into a {@code Tag}.
* Leading and trailing whitespaces will be trimmed.
*
* @throws IllegalValueException if the given {@code tag} is invalid.
*/
public static Tag parseTag(String tag) throws IllegalValueException {
requireNonNull(tag);
String trimmedTag = tag.trim();
if (!Tag.isValidTagName(trimmedTag)) {
throw new IllegalValueException(Tag.MESSAGE_TAG_CONSTRAINTS);
}
return new Tag(trimmedTag);
}

/**
Expand All @@ -86,7 +161,7 @@ public static Set<Tag> parseTags(Collection<String> tags) throws IllegalValueExc
requireNonNull(tags);
final Set<Tag> tagSet = new HashSet<>();
for (String tagName : tags) {
tagSet.add(new Tag(tagName));
tagSet.add(parseTag(tagName));
}
return tagSet;
}
Expand Down
13 changes: 5 additions & 8 deletions src/main/java/seedu/address/model/person/Address.java
@@ -1,8 +1,7 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.exceptions.IllegalValueException;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Person's address in the address book.
Expand All @@ -22,15 +21,13 @@ public class Address {
public final String value;

/**
* Validates given address.
* Constructs an {@code Address}.
*
* @throws IllegalValueException if given address string is invalid.
* @param address A valid address.
*/
public Address(String address) throws IllegalValueException {
public Address(String address) {
requireNonNull(address);
if (!isValidAddress(address)) {
throw new IllegalValueException(MESSAGE_ADDRESS_CONSTRAINTS);
}
checkArgument(isValidAddress(address), MESSAGE_ADDRESS_CONSTRAINTS);
this.value = address;
}

Expand Down
16 changes: 6 additions & 10 deletions src/main/java/seedu/address/model/person/Email.java
@@ -1,8 +1,7 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.exceptions.IllegalValueException;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Person's phone number in the address book.
Expand All @@ -17,17 +16,14 @@ public class Email {
public final String value;

/**
* Validates given email.
* Constructs an {@code Email}.
*
* @throws IllegalValueException if given email address string is invalid.
* @param email A valid email address.
*/
public Email(String email) throws IllegalValueException {
public Email(String email) {
requireNonNull(email);
String trimmedEmail = email.trim();
if (!isValidEmail(trimmedEmail)) {
throw new IllegalValueException(MESSAGE_EMAIL_CONSTRAINTS);
}
this.value = trimmedEmail;
checkArgument(isValidEmail(email), MESSAGE_EMAIL_CONSTRAINTS);
this.value = email;
}

/**
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/seedu/address/model/person/Name.java
@@ -1,8 +1,7 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.exceptions.IllegalValueException;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Person's name in the address book.
Expand All @@ -22,17 +21,14 @@ public class Name {
public final String fullName;

/**
* Validates given name.
* Constructs a {@code Name}.
*
* @throws IllegalValueException if given name string is invalid.
* @param name A valid name.
*/
public Name(String name) throws IllegalValueException {
public Name(String name) {
requireNonNull(name);
String trimmedName = name.trim();
if (!isValidName(trimmedName)) {
throw new IllegalValueException(MESSAGE_NAME_CONSTRAINTS);
}
this.fullName = trimmedName;
checkArgument(isValidName(name), MESSAGE_NAME_CONSTRAINTS);
this.fullName = name;
}

/**
Expand Down
16 changes: 6 additions & 10 deletions src/main/java/seedu/address/model/person/Phone.java
@@ -1,8 +1,7 @@
package seedu.address.model.person;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.exceptions.IllegalValueException;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Person's phone number in the address book.
Expand All @@ -17,17 +16,14 @@ public class Phone {
public final String value;

/**
* Validates given phone number.
* Constructs a {@code Phone}.
*
* @throws IllegalValueException if given phone string is invalid.
* @param phone A valid phone number.
*/
public Phone(String phone) throws IllegalValueException {
public Phone(String phone) {
requireNonNull(phone);
String trimmedPhone = phone.trim();
if (!isValidPhone(trimmedPhone)) {
throw new IllegalValueException(MESSAGE_PHONE_CONSTRAINTS);
}
this.value = trimmedPhone;
checkArgument(isValidPhone(phone), MESSAGE_PHONE_CONSTRAINTS);
this.value = phone;
}

/**
Expand Down
18 changes: 7 additions & 11 deletions src/main/java/seedu/address/model/tag/Tag.java
@@ -1,8 +1,7 @@
package seedu.address.model.tag;

import static java.util.Objects.requireNonNull;

import seedu.address.commons.exceptions.IllegalValueException;
import static seedu.address.commons.util.AppUtil.checkArgument;

/**
* Represents a Tag in the address book.
Expand All @@ -16,17 +15,14 @@ public class Tag {
public final String tagName;

/**
* Validates given tag name.
* Constructs a {@code Tag}.
*
* @throws IllegalValueException if the given tag name string is invalid.
* @param tagName A valid tag name.
*/
public Tag(String name) throws IllegalValueException {
requireNonNull(name);
String trimmedName = name.trim();
if (!isValidTagName(trimmedName)) {
throw new IllegalValueException(MESSAGE_TAG_CONSTRAINTS);
}
this.tagName = trimmedName;
public Tag(String tagName) {
requireNonNull(tagName);
checkArgument(isValidTagName(tagName), MESSAGE_TAG_CONSTRAINTS);
this.tagName = tagName;
}

/**
Expand Down
47 changes: 21 additions & 26 deletions src/main/java/seedu/address/model/util/SampleDataUtil.java
Expand Up @@ -3,7 +3,6 @@
import java.util.HashSet;
import java.util.Set;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.AddressBook;
import seedu.address.model.ReadOnlyAddressBook;
import seedu.address.model.person.Address;
Expand All @@ -19,30 +18,26 @@
*/
public class SampleDataUtil {
public static Person[] getSamplePersons() {
try {
return new Person[] {
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"),
new Address("Blk 30 Geylang Street 29, #06-40"),
getTagSet("friends")),
new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
getTagSet("colleagues", "friends")),
new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
getTagSet("neighbours")),
new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
getTagSet("family")),
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"),
new Address("Blk 47 Tampines Street 20, #17-35"),
getTagSet("classmates")),
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"),
new Address("Blk 45 Aljunied Street 85, #11-31"),
getTagSet("colleagues"))
};
} catch (IllegalValueException e) {
throw new AssertionError("sample data cannot be invalid", e);
}
return new Person[] {
new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"),
new Address("Blk 30 Geylang Street 29, #06-40"),
getTagSet("friends")),
new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"),
new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"),
getTagSet("colleagues", "friends")),
new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"),
new Address("Blk 11 Ang Mo Kio Street 74, #11-04"),
getTagSet("neighbours")),
new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"),
new Address("Blk 436 Serangoon Gardens Street 26, #16-43"),
getTagSet("family")),
new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"),
new Address("Blk 47 Tampines Street 20, #17-35"),
getTagSet("classmates")),
new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"),
new Address("Blk 45 Aljunied Street 85, #11-31"),
getTagSet("colleagues"))
};
}

public static ReadOnlyAddressBook getSampleAddressBook() {
Expand All @@ -60,7 +55,7 @@ public static ReadOnlyAddressBook getSampleAddressBook() {
/**
* Returns a tag set containing the list of strings given.
*/
public static Set<Tag> getTagSet(String... strings) throws IllegalValueException {
public static Set<Tag> getTagSet(String... strings) {
HashSet<Tag> tags = new HashSet<>();
for (String s : strings) {
tags.add(new Tag(s));
Expand Down

0 comments on commit fd47a3b

Please sign in to comment.