]> nmode's Git Repositories - signal-cli/blob - lib/src/main/java/org/asamk/signal/manager/api/Contact.java
Refactor manager lib package structure
[signal-cli] / lib / src / main / java / org / asamk / signal / manager / api / Contact.java
1 package org.asamk.signal.manager.api;
2
3 import org.whispersystems.signalservice.internal.util.Util;
4
5 import java.util.Objects;
6
7 public class Contact {
8
9 private final String givenName;
10
11 private final String familyName;
12
13 private final String color;
14
15 private final int messageExpirationTime;
16
17 private final boolean blocked;
18
19 private final boolean archived;
20
21 private final boolean profileSharingEnabled;
22
23 public Contact(
24 final String givenName,
25 final String familyName,
26 final String color,
27 final int messageExpirationTime,
28 final boolean blocked,
29 final boolean archived,
30 final boolean profileSharingEnabled
31 ) {
32 this.givenName = givenName;
33 this.familyName = familyName;
34 this.color = color;
35 this.messageExpirationTime = messageExpirationTime;
36 this.blocked = blocked;
37 this.archived = archived;
38 this.profileSharingEnabled = profileSharingEnabled;
39 }
40
41 private Contact(final Builder builder) {
42 givenName = builder.givenName;
43 familyName = builder.familyName;
44 color = builder.color;
45 messageExpirationTime = builder.messageExpirationTime;
46 blocked = builder.blocked;
47 archived = builder.archived;
48 profileSharingEnabled = builder.profileSharingEnabled;
49 }
50
51 public static Builder newBuilder() {
52 return new Builder();
53 }
54
55 public static Builder newBuilder(final Contact copy) {
56 Builder builder = new Builder();
57 builder.givenName = copy.getGivenName();
58 builder.familyName = copy.getFamilyName();
59 builder.color = copy.getColor();
60 builder.messageExpirationTime = copy.getMessageExpirationTime();
61 builder.blocked = copy.isBlocked();
62 builder.archived = copy.isArchived();
63 builder.profileSharingEnabled = copy.isProfileSharingEnabled();
64 return builder;
65 }
66
67 public String getName() {
68 final var noGivenName = Util.isEmpty(givenName);
69 final var noFamilyName = Util.isEmpty(familyName);
70
71 if (noGivenName && noFamilyName) {
72 return "";
73 } else if (noGivenName) {
74 return familyName;
75 } else if (noFamilyName) {
76 return givenName;
77 }
78
79 return givenName + " " + familyName;
80 }
81
82 public String getGivenName() {
83 return givenName;
84 }
85
86 public String getFamilyName() {
87 return familyName;
88 }
89
90 public String getColor() {
91 return color;
92 }
93
94 public int getMessageExpirationTime() {
95 return messageExpirationTime;
96 }
97
98 public boolean isBlocked() {
99 return blocked;
100 }
101
102 public boolean isArchived() {
103 return archived;
104 }
105
106 public boolean isProfileSharingEnabled() {
107 return profileSharingEnabled;
108 }
109
110 @Override
111 public boolean equals(final Object o) {
112 if (this == o) return true;
113 if (o == null || getClass() != o.getClass()) return false;
114 final Contact contact = (Contact) o;
115 return messageExpirationTime == contact.messageExpirationTime
116 && blocked == contact.blocked
117 && archived == contact.archived
118 && profileSharingEnabled == contact.profileSharingEnabled
119 && Objects.equals(givenName, contact.givenName)
120 && Objects.equals(familyName, contact.familyName)
121 && Objects.equals(color, contact.color);
122 }
123
124 @Override
125 public int hashCode() {
126 return Objects.hash(givenName,
127 familyName,
128 color,
129 messageExpirationTime,
130 blocked,
131 archived,
132 profileSharingEnabled);
133 }
134
135 public static final class Builder {
136
137 private String givenName;
138 private String familyName;
139 private String color;
140 private int messageExpirationTime;
141 private boolean blocked;
142 private boolean archived;
143 private boolean profileSharingEnabled;
144
145 private Builder() {
146 }
147
148 public Builder withGivenName(final String val) {
149 givenName = val;
150 return this;
151 }
152
153 public Builder withFamilyName(final String val) {
154 familyName = val;
155 return this;
156 }
157
158 public Builder withColor(final String val) {
159 color = val;
160 return this;
161 }
162
163 public Builder withMessageExpirationTime(final int val) {
164 messageExpirationTime = val;
165 return this;
166 }
167
168 public Builder withBlocked(final boolean val) {
169 blocked = val;
170 return this;
171 }
172
173 public Builder withArchived(final boolean val) {
174 archived = val;
175 return this;
176 }
177
178 public Builder withProfileSharingEnabled(final boolean val) {
179 profileSharingEnabled = val;
180 return this;
181 }
182
183 public Contact build() {
184 return new Contact(this);
185 }
186 }
187 }