forked from nus-cs2103-AY2021S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathPerson.java
More file actions
132 lines (110 loc) · 3.53 KB
/
Person.java
File metadata and controls
132 lines (110 loc) · 3.53 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package seedu.address.model.person;
import static seedu.address.commons.util.CollectionUtil.requireAllNonNull;
import java.util.Collections;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import seedu.address.model.tag.Tag;
/**
* Represents a Person in the address book.
* Guarantees: details are present and not null, field values are validated, immutable.
*/
public class Person {
// Identity fields
private final Name name;
private final Phone phone;
private final Email email;
// Data fields
private final Address address;
private final Remark remark;
private final Set<Tag> tags = new HashSet<>();
/**
* Every field must be present and not null.
*/
public Person(Name name, Phone phone, Email email, Address address, Remark remark, Set<Tag> tags) {
requireAllNonNull(name, phone, email, address, remark, tags);
this.name = name;
this.phone = phone;
this.email = email;
this.address = address;
this.remark = remark;
this.tags.addAll(tags);
}
public Name getName() {
return name;
}
public Phone getPhone() {
return phone;
}
public Email getEmail() {
return email;
}
public Address getAddress() {
return address;
}
public Remark getRemark() {
return remark;
}
/**
* Returns an immutable tag set, which throws {@code UnsupportedOperationException}
* if modification is attempted.
*/
public Set<Tag> getTags() {
return Collections.unmodifiableSet(tags);
}
/**
* Returns true if both persons have the same name.
* This defines a weaker notion of equality between two persons.
*/
public boolean isSamePerson(Person otherPerson) {
if (otherPerson == this) {
return true;
}
return otherPerson != null
&& otherPerson.getName().equals(getName());
}
/**
* Returns true if both persons have the same identity and data fields.
* This defines a stronger notion of equality between two persons.
*/
@Override
public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof Person)) {
return false;
}
Person otherPerson = (Person) other;
return otherPerson.getName().equals(getName())
&& otherPerson.getPhone().equals(getPhone())
&& otherPerson.getEmail().equals(getEmail())
&& otherPerson.getAddress().equals(getAddress())
&& otherPerson.getRemark().equals(getRemark())
&& otherPerson.getTags().equals(getTags());
}
@Override
public int hashCode() {
// use this method for custom fields hashing instead of implementing your own
return Objects.hash(name, phone, email, address, tags);
}
@Override
public String toString() {
final StringBuilder builder = new StringBuilder();
builder.append(getName())
.append("; Phone: ")
.append(getPhone())
.append("; Email: ")
.append(getEmail())
.append("; Address: ")
.append(getAddress())
.append("; Remark: ")
.append(getRemark());
Set<Tag> tags = getTags();
if (!tags.isEmpty()) {
builder.append("; Tags: ");
tags.forEach(builder::append);
}
return builder.toString();
}
}