import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.template.SoneAccessor;
+import net.pterodactylus.util.filter.Filter;
import net.pterodactylus.util.logging.Logging;
import freenet.keys.FreenetURI;
*
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
-public class Sone {
+public class Sone implements Fingerprintable, Comparable<Sone> {
/** comparator that sorts Sones by their nice name. */
public static final Comparator<Sone> NICE_NAME_COMPARATOR = new Comparator<Sone>() {
};
+ /** Filter to remove Sones that have not been downloaded. */
+ public static final Filter<Sone> EMPTY_SONE_FILTER = new Filter<Sone>() {
+
+ @Override
+ public boolean filterObject(Sone sone) {
+ return sone.getTime() != 0;
+ }
+ };
+
/** The logger. */
private static final Logger logger = Logging.getLogger(Sone.class);
private volatile long time;
/** The profile of this Sone. */
- private volatile Profile profile;
+ private volatile Profile profile = new Profile();
+
+ /** The client used by the Sone. */
+ private volatile Client client;
/** All friend Sones. */
private final Set<String> friendSones = Collections.synchronizedSet(new HashSet<String>());
*/
public Sone setRequestUri(FreenetURI requestUri) {
if (this.requestUri == null) {
- this.requestUri = requestUri.setDocName("Sone").setMetaString(new String[0]);
+ this.requestUri = requestUri.setKeyType("USK").setDocName("Sone").setMetaString(new String[0]);
return this;
}
if (!this.requestUri.equalsKeypair(requestUri)) {
*/
public Sone setInsertUri(FreenetURI insertUri) {
if (this.insertUri == null) {
- this.insertUri = insertUri.setDocName("Sone").setMetaString(new String[0]);
+ this.insertUri = insertUri.setKeyType("USK").setDocName("Sone").setMetaString(new String[0]);
return this;
}
if (!this.insertUri.equalsKeypair(insertUri)) {
}
/**
+ * Returns the client used by this Sone.
+ *
+ * @return The client used by this Sone, or {@code null}
+ */
+ public Client getClient() {
+ return client;
+ }
+
+ /**
+ * Sets the client used by this Sone.
+ *
+ * @param client
+ * The client used by this Sone, or {@code null}
+ * @return This Sone (for method chaining)
+ */
+ public Sone setClient(Client client) {
+ this.client = client;
+ return this;
+ }
+
+ /**
* Returns all friend Sones of this Sone.
*
* @return The friend Sones of this Sone
* @return This Sone (for method chaining)
*/
public synchronized Sone setPosts(Collection<Post> posts) {
- this.posts.clear();
- this.posts.addAll(posts);
+ synchronized (this) {
+ this.posts.clear();
+ this.posts.addAll(posts);
+ }
return this;
}
return this;
}
+ //
+ // FINGERPRINTABLE METHODS
+ //
+
/**
- * Returns a fingerprint of this Sone. The fingerprint only depends on data
- * that is actually stored when a Sone is inserted. The fingerprint can be
- * used to detect changes in Sone data and can also be used to detect if
- * previous changes are reverted.
- *
- * @return The fingerprint of this Sone
+ * {@inheritDoc}
*/
+ @Override
public synchronized String getFingerprint() {
StringBuilder fingerprint = new StringBuilder();
- fingerprint.append("Profile(");
- if (profile.getFirstName() != null) {
- fingerprint.append("FirstName(").append(profile.getFirstName()).append(')');
- }
- if (profile.getMiddleName() != null) {
- fingerprint.append("MiddleName(").append(profile.getMiddleName()).append(')');
- }
- if (profile.getLastName() != null) {
- fingerprint.append("LastName(").append(profile.getLastName()).append(')');
- }
- if (profile.getBirthDay() != null) {
- fingerprint.append("BirthDay(").append(profile.getBirthDay()).append(')');
- }
- if (profile.getBirthMonth() != null) {
- fingerprint.append("BirthMonth(").append(profile.getBirthMonth()).append(')');
- }
- if (profile.getBirthYear() != null) {
- fingerprint.append("BirthYear(").append(profile.getBirthYear()).append(')');
- }
- fingerprint.append(")");
+ fingerprint.append(profile.getFingerprint());
fingerprint.append("Posts(");
for (Post post : getPosts()) {
}
//
+ // INTERFACE Comparable<Sone>
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int compareTo(Sone sone) {
+ return NICE_NAME_COMPARATOR.compare(this, sone);
+ }
+
+ //
// OBJECT METHODS
//