This repository has been archived by the owner on Mar 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
PersonBuilder.java
87 lines (73 loc) · 2.63 KB
/
PersonBuilder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package seedu.address.testutil;
import java.util.Set;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
import seedu.address.model.person.Person;
import seedu.address.model.person.Phone;
import seedu.address.model.person.ReadOnlyPerson;
import seedu.address.model.tag.Tag;
import seedu.address.model.util.SampleDataUtil;
/**
* A utility class to help with building Person objects.
*/
public class PersonBuilder {
public static final String DEFAULT_NAME = "Alice Pauline";
public static final String DEFAULT_PHONE = "85355255";
public static final String DEFAULT_EMAIL = "alice@gmail.com";
public static final String DEFAULT_ADDRESS = "123, Jurong West Ave 6, #08-111";
public static final String DEFAULT_TAGS = "friends";
private Person person;
public PersonBuilder() {
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);
}
/**
* Initializes the PersonBuilder with the data of {@code personToCopy}.
*/
public PersonBuilder(ReadOnlyPerson personToCopy) {
this.person = new Person(personToCopy);
}
/**
* Sets the {@code Name} of the {@code Person} that we are building.
*/
public PersonBuilder withName(String name) {
this.person.setName(new Name(name));
return this;
}
/**
* 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) {
this.person.setTags(SampleDataUtil.getTagSet(tags));
return this;
}
/**
* Sets the {@code Address} of the {@code Person} that we are building.
*/
public PersonBuilder withAddress(String address) {
this.person.setAddress(new Address(address));
return this;
}
/**
* Sets the {@code Phone} of the {@code Person} that we are building.
*/
public PersonBuilder withPhone(String phone) {
this.person.setPhone(new Phone(phone));
return this;
}
/**
* Sets the {@code Email} of the {@code Person} that we are building.
*/
public PersonBuilder withEmail(String email) {
this.person.setEmail(new Email(email));
return this;
}
public Person build() {
return this.person;
}
}