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

Commit

Permalink
Remove unncessary IllegalValueException catches and throws in code base
Browse files Browse the repository at this point in the history
In the previous commits, we have fixed up the Name, Email, Address and
Tag classes to not throw the checked IllegalValueException any more.

As a result of these changes, there are many other call sites in the
code base which do not need to throw or catch IllegalValueException any
more.  Let's clean up these call sites.
  • Loading branch information
pyokagan committed Dec 5, 2017
1 parent fecd75e commit d2e3f8d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 42 deletions.
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
23 changes: 7 additions & 16 deletions src/test/java/seedu/address/testutil/PersonBuilder.java
Expand Up @@ -2,7 +2,6 @@

import java.util.Set;

import seedu.address.commons.exceptions.IllegalValueException;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand All @@ -26,16 +25,12 @@ public class PersonBuilder {
private Person person;

public PersonBuilder() {
try {
Name defaultName = new Name(DEFAULT_NAME);
Phone defaultPhone = new Phone(DEFAULT_PHONE);
Email defaultEmail = new Email(DEFAULT_EMAIL);
Address defaultAddress = new Address(DEFAULT_ADDRESS);
Set<Tag> defaultTags = SampleDataUtil.getTagSet(DEFAULT_TAGS);
this.person = new Person(defaultName, defaultPhone, defaultEmail, defaultAddress, defaultTags);
} catch (IllegalValueException ive) {
throw new AssertionError("Default person's values are invalid.");
}
Name defaultName = new Name(DEFAULT_NAME);
Phone defaultPhone = new Phone(DEFAULT_PHONE);
Email defaultEmail = new Email(DEFAULT_EMAIL);
Address defaultAddress = new Address(DEFAULT_ADDRESS);
Set<Tag> defaultTags = SampleDataUtil.getTagSet(DEFAULT_TAGS);
this.person = new Person(defaultName, defaultPhone, defaultEmail, defaultAddress, defaultTags);
}

/**
Expand All @@ -57,11 +52,7 @@ public PersonBuilder withName(String name) {
* Parses the {@code tags} into a {@code Set<Tag>} and set it to the {@code Person} that we are building.
*/
public PersonBuilder withTags(String ... tags) {
try {
this.person.setTags(SampleDataUtil.getTagSet(tags));
} catch (IllegalValueException ive) {
throw new IllegalArgumentException("tags are expected to be unique.");
}
this.person.setTags(SampleDataUtil.getTagSet(tags));
return this;
}

Expand Down

0 comments on commit d2e3f8d

Please sign in to comment.