+public class Profile implements Fingerprintable {
+
+ /** The Sone this profile belongs to. */
+ private final Sone sone;
+
+ /** The first name. */
+ private volatile String firstName;
+
+ /** The middle name(s). */
+ private volatile String middleName;
+
+ /** The last name. */
+ private volatile String lastName;
+
+ /** The day of the birth date. */
+ private volatile Integer birthDay;
+
+ /** The month of the birth date. */
+ private volatile Integer birthMonth;
+
+ /** 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(Sone sone) {
+ this.sone = sone;
+ }
+
+ /**
+ * Creates a copy of a profile.
+ *
+ * @param profile
+ * The profile to copy
+ */
+ public Profile(Profile profile) {
+ 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);
+ }
+
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * 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
+ */
+ public String getFirstName() {
+ return firstName;
+ }
+
+ /**
+ * Sets the first name.
+ *
+ * @param firstName
+ * The first name to set
+ * @return This profile (for method chaining)
+ */
+ public Profile setFirstName(String firstName) {
+ this.firstName = firstName;
+ return this;
+ }
+
+ /**
+ * Returns the middle name(s).
+ *
+ * @return The middle name
+ */
+ public String getMiddleName() {
+ return middleName;
+ }
+
+ /**
+ * Sets the middle name.
+ *
+ * @param middleName
+ * The middle name to set
+ * @return This profile (for method chaining)
+ */
+ public Profile setMiddleName(String middleName) {
+ this.middleName = middleName;
+ return this;
+ }
+
+ /**
+ * Returns the last name.
+ *
+ * @return The last name
+ */
+ public String getLastName() {
+ return lastName;
+ }
+
+ /**
+ * Sets the last name.
+ *
+ * @param lastName
+ * The last name to set
+ * @return This profile (for method chaining)
+ */
+ public Profile setLastName(String lastName) {
+ this.lastName = lastName;
+ return this;
+ }
+
+ /**
+ * Returns the day of the birth date.
+ *
+ * @return The day of the birth date (from 1 to 31)
+ */
+ public Integer getBirthDay() {
+ return birthDay;
+ }
+
+ /**
+ * Sets the day of the birth date.
+ *
+ * @param birthDay
+ * The day of the birth date (from 1 to 31)
+ * @return This profile (for method chaining)
+ */
+ public Profile setBirthDay(Integer birthDay) {
+ this.birthDay = birthDay;
+ return this;
+ }
+
+ /**
+ * Returns the month of the birth date.
+ *
+ * @return The month of the birth date (from 1 to 12)
+ */
+ public Integer getBirthMonth() {
+ return birthMonth;
+ }
+
+ /**
+ * Sets the month of the birth date.
+ *
+ * @param birthMonth
+ * The month of the birth date (from 1 to 12)
+ * @return This profile (for method chaining)
+ */
+ public Profile setBirthMonth(Integer birthMonth) {
+ this.birthMonth = birthMonth;
+ return this;
+ }
+
+ /**
+ * Returns the year of the birth date.
+ *
+ * @return The year of the birth date
+ */
+ public Integer getBirthYear() {
+ return birthYear;
+ }
+
+ /**
+ * 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;
+ }
+ checkArgument(avatar.getSone().equals(sone), "avatar must belong to Sone");
+ this.avatar = avatar.getId();
+ return this;
+ }
+
+ /**
+ * Sets the year of the birth date.
+ *
+ * @param birthYear
+ * The year of the birth date
+ * @return This profile (for method chaining)
+ */
+ public Profile setBirthYear(Integer birthYear) {
+ this.birthYear = birthYear;
+ return this;
+ }
+
+ /**
+ * Returns the fields of this profile.
+ *
+ * @return The fields of this profile
+ */
+ public List<Field> getFields() {
+ return new ArrayList<Field>(fields);
+ }
+
+ /**
+ * Returns whether this profile contains the given field.
+ *
+ * @param field
+ * The field to check for
+ * @return {@code true} if this profile contains the field, false otherwise
+ */
+ public boolean hasField(Field field) {
+ return fields.contains(field);
+ }
+
+ /**
+ * Returns the field with the given ID.
+ *
+ * @param fieldId
+ * The ID of the field to get
+ * @return The field, or {@code null} if this profile does not contain a
+ * field with the given ID
+ */
+ public Field getFieldById(String fieldId) {
+ checkNotNull(fieldId, "fieldId must not be null");
+ for (Field field : fields) {
+ if (field.getId().equals(fieldId)) {
+ return field;
+ }
+ }
+ return null;
+ }