Add birth date to profile.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Profile.java
1 /*
2  * FreenetSone - Profile.java - Copyright © 2010 David Roden
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17
18 package net.pterodactylus.sone.data;
19
20 /**
21  * A profile stores personal information about a {@link Sone}. All information
22  * is optional and can be {@code null}.
23  *
24  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
25  */
26 public class Profile {
27
28         /** Whether the profile was modified. */
29         private boolean modified;
30
31         /** The first name. */
32         private String firstName;
33
34         /** The middle name(s). */
35         private String middleName;
36
37         /** The last name. */
38         private String lastName;
39
40         /** The day of the birth date. */
41         private Integer birthDay;
42
43         /** The month of the birth date. */
44         private Integer birthMonth;
45
46         /** The year of the birth date. */
47         private Integer birthYear;
48
49         /**
50          * Creates a new empty profile.
51          */
52         public Profile() {
53                 /* do nothing. */
54         }
55
56         /**
57          * Creates a copy of a profile.
58          *
59          * @param profile
60          *            The profile to copy
61          */
62         public Profile(Profile profile) {
63                 if (profile == null) {
64                         return;
65                 }
66                 this.firstName = profile.firstName;
67                 this.middleName = profile.middleName;
68                 this.lastName = profile.lastName;
69                 this.birthDay = profile.birthDay;
70                 this.birthMonth = profile.birthMonth;
71                 this.birthYear = profile.birthYear;
72         }
73
74         //
75         // ACCESSORS
76         //
77
78         /**
79          * Returns whether this profile was modified after creation. To clear the
80          * “is modified” flag you need to create a new profile from this one using
81          * the {@link #Profile(Profile)} constructor.
82          *
83          * @return {@code true} if this profile was modified after creation,
84          *         {@code false} otherwise
85          */
86         public boolean isModified() {
87                 return modified;
88         }
89
90         /**
91          * Returns the first name.
92          *
93          * @return The first name
94          */
95         public String getFirstName() {
96                 return firstName;
97         }
98
99         /**
100          * Sets the first name.
101          *
102          * @param firstName
103          *            The first name to set
104          * @return This profile (for method chaining)
105          */
106         public Profile setFirstName(String firstName) {
107                 modified |= ((firstName != null) && (!firstName.equals(this.firstName))) || (this.firstName != null);
108                 this.firstName = firstName;
109                 return this;
110         }
111
112         /**
113          * Returns the middle name(s).
114          *
115          * @return The middle name
116          */
117         public String getMiddleName() {
118                 return middleName;
119         }
120
121         /**
122          * Sets the middle name.
123          *
124          * @param middleName
125          *            The middle name to set
126          * @return This profile (for method chaining)
127          */
128         public Profile setMiddleName(String middleName) {
129                 modified |= ((middleName != null) && (!middleName.equals(this.middleName))) || (this.middleName != null);
130                 this.middleName = middleName;
131                 return this;
132         }
133
134         /**
135          * Returns the last name.
136          *
137          * @return The last name
138          */
139         public String getLastName() {
140                 return lastName;
141         }
142
143         /**
144          * Sets the last name.
145          *
146          * @param lastName
147          *            The last name to set
148          * @return This profile (for method chaining)
149          */
150         public Profile setLastName(String lastName) {
151                 modified |= ((lastName != null) && (!lastName.equals(this.lastName))) || (this.lastName != null);
152                 this.lastName = lastName;
153                 return this;
154         }
155
156         /**
157          * Returns the day of the birth date.
158          *
159          * @return The day of the birth date (from 1 to 31)
160          */
161         public Integer getBirthDay() {
162                 return birthDay;
163         }
164
165         /**
166          * Sets the day of the birth date.
167          *
168          * @param birthDay
169          *            The day of the birth date (from 1 to 31)
170          * @return This profile (for method chaining)
171          */
172         public Profile setBirthDay(Integer birthDay) {
173                 modified |= ((birthDay != null) && (!birthDay.equals(this.birthDay))) || (this.birthDay != null);
174                 this.birthDay = birthDay;
175                 return this;
176         }
177
178         /**
179          * Returns the month of the birth date.
180          *
181          * @return The month of the birth date (from 1 to 12)
182          */
183         public Integer getBirthMonth() {
184                 return birthMonth;
185         }
186
187         /**
188          * Sets the month of the birth date.
189          *
190          * @param birthMonth
191          *            The month of the birth date (from 1 to 12)
192          * @return This profile (for method chaining)
193          */
194         public Profile setBirthMonth(Integer birthMonth) {
195                 modified |= ((birthMonth != null) && (!birthMonth.equals(this.birthMonth))) || (this.birthMonth != null);
196                 this.birthMonth = birthMonth;
197                 return this;
198         }
199
200         /**
201          * Returns the year of the birth date.
202          *
203          * @return The year of the birth date
204          */
205         public Integer getBirthYear() {
206                 return birthYear;
207         }
208
209         /**
210          * Sets the year of the birth date.
211          *
212          * @param birthYear
213          *            The year of the birth date
214          * @return This profile (for method chaining)
215          */
216         public Profile setBirthYear(Integer birthYear) {
217                 modified |= ((birthYear != null) && (!birthYear.equals(this.birthYear))) || (this.birthYear != null);
218                 this.birthYear = birthYear;
219                 return this;
220         }
221
222 }