Implement Fingerprintable interface in Profile.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 10 Jan 2011 08:06:06 +0000 (09:06 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 10 Jan 2011 08:06:06 +0000 (09:06 +0100)
src/main/java/net/pterodactylus/sone/data/Profile.java
src/main/java/net/pterodactylus/sone/data/Sone.java

index 7c29430..2d2f6d4 100644 (file)
@@ -23,7 +23,7 @@ package net.pterodactylus.sone.data;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public class Profile {
+public class Profile implements Fingerprintable {
 
        /** Whether the profile was modified. */
        private volatile boolean modified;
@@ -219,4 +219,38 @@ public class Profile {
                return this;
        }
 
+       //
+       // INTERFACE Fingerprintable
+       //
+
+       /**
+        * {@inheritDoc}
+        */
+       @Override
+       public String getFingerprint() {
+               StringBuilder fingerprint = new StringBuilder();
+               fingerprint.append("Profile(");
+               if (firstName != null) {
+                       fingerprint.append("FirstName(").append(firstName).append(')');
+               }
+               if (middleName != null) {
+                       fingerprint.append("MiddleName(").append(middleName).append(')');
+               }
+               if (lastName != null) {
+                       fingerprint.append("LastName(").append(lastName).append(')');
+               }
+               if (birthDay != null) {
+                       fingerprint.append("BirthDay(").append(birthDay).append(')');
+               }
+               if (birthMonth != null) {
+                       fingerprint.append("BirthMonth(").append(birthMonth).append(')');
+               }
+               if (birthYear != null) {
+                       fingerprint.append("BirthYear(").append(birthYear).append(')');
+               }
+               fingerprint.append(")");
+
+               return fingerprint.toString();
+       }
+
 }
index c145b82..03dff75 100644 (file)
@@ -590,26 +590,7 @@ public class Sone implements Fingerprintable {
        @Override
        public synchronized String getFingerprint() {
                StringBuilder fingerprint = new StringBuilder();
-               fingerprint.append("Profile(");
-               if (profile.getFirstName() != null) {
-                       fingerprint.append("FirstName(").append(profile.getFirstName()).append(')');
-               }
-               if (profile.getMiddleName() != null) {
-                       fingerprint.append("MiddleName(").append(profile.getMiddleName()).append(')');
-               }
-               if (profile.getLastName() != null) {
-                       fingerprint.append("LastName(").append(profile.getLastName()).append(')');
-               }
-               if (profile.getBirthDay() != null) {
-                       fingerprint.append("BirthDay(").append(profile.getBirthDay()).append(')');
-               }
-               if (profile.getBirthMonth() != null) {
-                       fingerprint.append("BirthMonth(").append(profile.getBirthMonth()).append(')');
-               }
-               if (profile.getBirthYear() != null) {
-                       fingerprint.append("BirthYear(").append(profile.getBirthYear()).append(')');
-               }
-               fingerprint.append(")");
+               fingerprint.append(profile.getFingerprint());
 
                fingerprint.append("Posts(");
                for (Post post : getPosts()) {