Copying a null profile results in an empty 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         /**
41          * Creates a new empty profile.
42          */
43         public Profile() {
44                 /* do nothing. */
45         }
46
47         /**
48          * Creates a copy of a profile.
49          *
50          * @param profile
51          *            The profile to copy
52          */
53         public Profile(Profile profile) {
54                 if (profile == null) {
55                         return;
56                 }
57                 this.firstName = profile.firstName;
58                 this.middleName = profile.middleName;
59                 this.lastName = profile.lastName;
60         }
61
62         //
63         // ACCESSORS
64         //
65
66         /**
67          * Returns whether this profile was modified after creation. To clear the
68          * “is modified” flag you need to create a new profile from this one using
69          * the {@link #Profile(Profile)} constructor.
70          *
71          * @return {@code true} if this profile was modified after creation,
72          *         {@code false} otherwise
73          */
74         public boolean isModified() {
75                 return modified;
76         }
77
78         /**
79          * Returns the first name.
80          *
81          * @return The first name
82          */
83         public String getFirstName() {
84                 return firstName;
85         }
86
87         /**
88          * Sets the first name.
89          *
90          * @param firstName
91          *            The first name to set
92          * @return This profile (for method chaining)
93          */
94         public Profile setFirstName(String firstName) {
95                 modified |= ((firstName != null) && (!firstName.equals(this.firstName))) || (this.firstName != null);
96                 this.firstName = firstName;
97                 return this;
98         }
99
100         /**
101          * Returns the middle name(s).
102          *
103          * @return The middle name
104          */
105         public String getMiddleName() {
106                 return middleName;
107         }
108
109         /**
110          * Sets the middle name.
111          *
112          * @param middleName
113          *            The middle name to set
114          * @return This profile (for method chaining)
115          */
116         public Profile setMiddleName(String middleName) {
117                 modified |= ((middleName != null) && (!middleName.equals(this.middleName))) || (this.middleName != null);
118                 this.middleName = middleName;
119                 return this;
120         }
121
122         /**
123          * Returns the last name.
124          *
125          * @return The last name
126          */
127         public String getLastName() {
128                 return lastName;
129         }
130
131         /**
132          * Sets the last name.
133          *
134          * @param lastName
135          *            The last name to set
136          * @return This profile (for method chaining)
137          */
138         public Profile setLastName(String lastName) {
139                 modified |= ((lastName != null) && (!lastName.equals(this.lastName))) || (this.lastName != null);
140                 this.lastName = lastName;
141                 return this;
142         }
143
144 }