Allow method chaining in 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                 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          * @return This profile (for method chaining)
90          */
91         public Profile setFirstName(String firstName) {
92                 modified |= ((firstName != null) && (!firstName.equals(this.firstName))) || (this.firstName != null);
93                 this.firstName = firstName;
94                 return this;
95         }
96
97         /**
98          * Returns the middle name(s).
99          *
100          * @return The middle name
101          */
102         public String getMiddleName() {
103                 return middleName;
104         }
105
106         /**
107          * Sets the middle name.
108          *
109          * @param middleName
110          *            The middle name to set
111          * @return This profile (for method chaining)
112          */
113         public Profile setMiddleName(String middleName) {
114                 modified |= ((middleName != null) && (!middleName.equals(this.middleName))) || (this.middleName != null);
115                 this.middleName = middleName;
116                 return this;
117         }
118
119         /**
120          * Returns the last name.
121          *
122          * @return The last name
123          */
124         public String getLastName() {
125                 return lastName;
126         }
127
128         /**
129          * Sets the last name.
130          *
131          * @param lastName
132          *            The last name to set
133          * @return This profile (for method chaining)
134          */
135         public Profile setLastName(String lastName) {
136                 modified |= ((lastName != null) && (!lastName.equals(this.lastName))) || (this.lastName != null);
137                 this.lastName = lastName;
138                 return this;
139         }
140
141 }