* <dt>niceName</dt>
* <dd>Will show a combination of first name, middle name, and last name, if
* available, otherwise the username of the Sone is returned.</dd>
+ * <dt>isFriend</dt>
+ * <dd>Will return {@code true} if the sone in question is a friend of the
+ * currently logged in Sone (as determined by accessing the “currentSone”
+ * variable of the given {@link DataProvider}).</dd>
+ * <dt>isCurrent</dt>
+ * <dd>Will return {@code true} if the sone in question is the currently logged
+ * in Sone.</dd>
* </dl>
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
public Object get(DataProvider dataProvider, Object object, String member) {
Sone sone = (Sone) object;
if (member.equals("niceName")) {
- Profile profile = sone.getProfile();
- String firstName = profile.getFirstName();
- String middleName = profile.getMiddleName();
- String lastName = profile.getLastName();
- if (firstName == null) {
- if (lastName == null) {
- return sone.getName();
- }
- return lastName;
- }
- return firstName + ((middleName != null) ? " " + middleName : "") + ((lastName != null) ? " " + lastName : "");
+ return getNiceName(sone);
+ } else if (member.equals("isFriend")) {
+ Sone currentSone = (Sone) dataProvider.getData("currentSone");
+ return currentSone.hasFriend(sone) ? true : null;
+ } else if (member.equals("isCurrent")) {
+ Sone currentSone = (Sone) dataProvider.getData("currentSone");
+ return currentSone.equals(sone);
+ } else if (member.equals("isBlocked")) {
+ Sone currentSone = (Sone) dataProvider.getData("currentSone");
+ return currentSone.isSoneBlocked(sone.getId());
}
return super.get(dataProvider, object, member);
}
+ //
+ // STATIC METHODS
+ //
+
+ /**
+ * Returns the nice name of the given Sone.
+ *
+ * @param sone
+ * The Sone to get the nice name for
+ * @return The nice name of the Sone
+ */
+ public static String getNiceName(Sone sone) {
+ Profile profile = sone.getProfile();
+ String firstName = profile.getFirstName();
+ String middleName = profile.getMiddleName();
+ String lastName = profile.getLastName();
+ if (firstName == null) {
+ if (lastName == null) {
+ return sone.getName();
+ }
+ return lastName;
+ }
+ return firstName + ((middleName != null) ? " " + middleName : "") + ((lastName != null) ? " " + lastName : "");
+ }
+
}