X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FProfile.java;fp=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FProfile.java;h=aa6ff46c043f21c0fd4f18d83e2ec5ca678b447a;hp=6b44d10eac29733242f4b24239e906f8ac1e04c6;hb=63df577f7ced52acfa93e4a7f329292069d8ba9d;hpb=c513e3329a397d0ebc17fe672f41c7d9d21122c7 diff --git a/src/main/java/net/pterodactylus/sone/data/Profile.java b/src/main/java/net/pterodactylus/sone/data/Profile.java index 6b44d10..aa6ff46 100644 --- a/src/main/java/net/pterodactylus/sone/data/Profile.java +++ b/src/main/java/net/pterodactylus/sone/data/Profile.java @@ -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); } @@ -198,6 +206,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 +403,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(')');