Add “is modified” flag.
[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 User}. 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                 this.firstName = profile.firstName;
55                 this.middleName = profile.middleName;
56                 this.lastName = profile.lastName;
57         }
58
59         //
60         // ACCESSORS
61         //
62
63         /**
64          * Returns whether this profile was modified after creation. To clear the
65          * “is modified” flag you need to create a new profile from this one using
66          * the {@link #Profile(Profile)} constructor.
67          *
68          * @return {@code true} if this profile was modified after creation,
69          *         {@code false} otherwise
70          */
71         public boolean isModified() {
72                 return modified;
73         }
74
75         /**
76          * Returns the first name.
77          *
78          * @return The first name
79          */
80         public String getFirstName() {
81                 return firstName;
82         }
83
84         /**
85          * Sets the first name.
86          *
87          * @param firstName
88          *            The first name to set
89          */
90         public void setFirstName(String firstName) {
91                 modified |= ((firstName != null) && (!firstName.equals(this.firstName))) || (this.firstName != null);
92                 this.firstName = firstName;
93         }
94
95         /**
96          * Returns the middle name(s).
97          *
98          * @return The middle name
99          */
100         public String getMiddleName() {
101                 return middleName;
102         }
103
104         /**
105          * Sets the middle name.
106          *
107          * @param middleName
108          *            The middle name to set
109          */
110         public void setMiddleName(String middleName) {
111                 modified |= ((middleName != null) && (!middleName.equals(this.middleName))) || (this.middleName != null);
112                 this.middleName = middleName;
113         }
114
115         /**
116          * Returns the last name.
117          *
118          * @return The last name
119          */
120         public String getLastName() {
121                 return lastName;
122         }
123
124         /**
125          * Sets the last name.
126          *
127          * @param lastName
128          *            The last name to set
129          */
130         public void setLastName(String lastName) {
131                 modified |= ((lastName != null) && (!lastName.equals(this.lastName))) || (this.lastName != null);
132                 this.lastName = lastName;
133         }
134
135 }