Allow method chaining in Profile.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Profile.java
index eeb04a4..242c96e 100644 (file)
 package net.pterodactylus.sone.data;
 
 /**
- * A profile stores personal information about a {@link User}. All information
+ * A profile stores personal information about a {@link Sone}. All information
  * is optional and can be {@code null}.
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 public class Profile {
 
+       /** Whether the profile was modified. */
+       private boolean modified;
+
        /** The first name. */
        private String firstName;
 
@@ -58,6 +61,18 @@ public class Profile {
        //
 
        /**
+        * Returns whether this profile was modified after creation. To clear the
+        * “is modified” flag you need to create a new profile from this one using
+        * the {@link #Profile(Profile)} constructor.
+        *
+        * @return {@code true} if this profile was modified after creation,
+        *         {@code false} otherwise
+        */
+       public boolean isModified() {
+               return modified;
+       }
+
+       /**
         * Returns the first name.
         *
         * @return The first name
@@ -71,9 +86,12 @@ public class Profile {
         *
         * @param firstName
         *            The first name to set
+        * @return This profile (for method chaining)
         */
-       public void setFirstName(String firstName) {
+       public Profile setFirstName(String firstName) {
+               modified |= ((firstName != null) && (!firstName.equals(this.firstName))) || (this.firstName != null);
                this.firstName = firstName;
+               return this;
        }
 
        /**
@@ -90,9 +108,12 @@ public class Profile {
         *
         * @param middleName
         *            The middle name to set
+        * @return This profile (for method chaining)
         */
-       public void setMiddleName(String middleName) {
+       public Profile setMiddleName(String middleName) {
+               modified |= ((middleName != null) && (!middleName.equals(this.middleName))) || (this.middleName != null);
                this.middleName = middleName;
+               return this;
        }
 
        /**
@@ -109,9 +130,12 @@ public class Profile {
         *
         * @param lastName
         *            The last name to set
+        * @return This profile (for method chaining)
         */
-       public void setLastName(String lastName) {
+       public Profile setLastName(String lastName) {
+               modified |= ((lastName != null) && (!lastName.equals(this.lastName))) || (this.lastName != null);
                this.lastName = lastName;
+               return this;
        }
 
 }