From 22a4aa8c03feedf20036c61635fb9071ac15707c Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 10 Jan 2011 09:06:06 +0100 Subject: [PATCH] Implement Fingerprintable interface in Profile. --- .../java/net/pterodactylus/sone/data/Profile.java | 36 +++++++++++++++++++++- .../java/net/pterodactylus/sone/data/Sone.java | 21 +------------ 2 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/data/Profile.java b/src/main/java/net/pterodactylus/sone/data/Profile.java index 7c29430..2d2f6d4 100644 --- a/src/main/java/net/pterodactylus/sone/data/Profile.java +++ b/src/main/java/net/pterodactylus/sone/data/Profile.java @@ -23,7 +23,7 @@ package net.pterodactylus.sone.data; * * @author David ‘Bombe’ Roden */ -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(); + } + } diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index c145b82..03dff75 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -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()) { -- 2.7.4