/*
- * Sone - Profile.java - Copyright © 2010 David Roden
+ * Sone - Profile.java - Copyright © 2010–2012 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
*/
public class Profile implements Fingerprintable {
+ /** The Sone this profile belongs to. */
+ private final Sone sone;
+
/** The first name. */
private volatile String firstName;
/** 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<Field> fields = Collections.synchronizedList(new ArrayList<Field>());
/**
* Creates a new empty profile.
+ *
+ * @param sone
+ * The Sone this profile belongs to
*/
- public Profile() {
- /* do nothing. */
+ public Profile(Sone sone) {
+ this.sone = sone;
}
/**
* 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);
}
//
/**
+ * 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
}
/**
+ * 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
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(')');