X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FProfile.java;h=6c0b435f11e50caaeec1865eadbb802dc552a2c5;hp=8d4306d268315bf6d95b2ff12ec69ddc52d3577c;hb=c9e306ac8e3ada846e87a0cc256a20fc148f381c;hpb=33f333b35a73d3d4a4e79f41e9dd7b342db87b1a diff --git a/src/main/java/net/pterodactylus/sone/data/Profile.java b/src/main/java/net/pterodactylus/sone/data/Profile.java index 8d4306d..6c0b435 100644 --- a/src/main/java/net/pterodactylus/sone/data/Profile.java +++ b/src/main/java/net/pterodactylus/sone/data/Profile.java @@ -1,5 +1,5 @@ /* - * FreenetSone - Profile.java - Copyright © 2010 David Roden + * Sone - Profile.java - Copyright © 2010 David Roden * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -32,6 +32,9 @@ import net.pterodactylus.util.validation.Validation; */ public class Profile implements Fingerprintable { + /** The Sone this profile belongs to. */ + private final Sone sone; + /** The first name. */ private volatile String firstName; @@ -50,14 +53,20 @@ public class Profile implements Fingerprintable { /** The year of the birth date. */ private volatile Integer birthYear; + /** The ID of the avatar image. */ + private volatile String avatar; + /** Additional fields in the profile. */ private final List fields = Collections.synchronizedList(new ArrayList()); /** * Creates a new empty profile. + * + * @param sone + * The Sone this profile belongs to */ - public Profile() { - /* do nothing. */ + public Profile(Sone sone) { + this.sone = sone; } /** @@ -67,15 +76,14 @@ public class Profile implements Fingerprintable { * The profile to copy */ public Profile(Profile profile) { - if (profile == null) { - return; - } + this.sone = profile.sone; this.firstName = profile.firstName; this.middleName = profile.middleName; this.lastName = profile.lastName; this.birthDay = profile.birthDay; this.birthMonth = profile.birthMonth; this.birthYear = profile.birthYear; + this.avatar = profile.avatar; this.fields.addAll(profile.fields); } @@ -84,6 +92,15 @@ public class Profile implements Fingerprintable { // /** + * Returns the Sone this profile belongs to. + * + * @return The Sone this profile belongs to + */ + public Sone getSone() { + return sone; + } + + /** * Returns the first name. * * @return The first name @@ -198,6 +215,34 @@ public class Profile implements Fingerprintable { } /** + * Returns the ID of the currently selected avatar image. + * + * @return The ID of the currently selected avatar image, or {@code null} if + * no avatar is selected. + */ + public String getAvatar() { + return avatar; + } + + /** + * Sets the avatar image. + * + * @param avatar + * The new avatar image, or {@code null} to not select an avatar + * image. + * @return This Sone + */ + public Profile setAvatar(Image avatar) { + if (avatar == null) { + this.avatar = null; + return this; + } + Validation.begin().isEqual("Image Owner", avatar.getSone(), sone).check(); + this.avatar = avatar.getId(); + return this; + } + + /** * Sets the year of the birth date. * * @param birthYear @@ -367,6 +412,9 @@ public class Profile implements Fingerprintable { if (birthYear != null) { fingerprint.append("BirthYear(").append(birthYear).append(')'); } + if (avatar != null) { + fingerprint.append("Avatar(").append(avatar).append(')'); + } fingerprint.append("ContactInformation("); for (Field field : fields) { fingerprint.append(field.getName()).append('(').append(field.getValue()).append(')');