X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSone.java;h=4bd60cca22295582e2af550382c73064dabf8fc8;hb=eef0d7c1f6624cb4d94ebb56571486eb75324eef;hp=03dff753563a50a7932047239fb48be29b2da90b;hpb=f4ea1e1b3526175e255831c975d6eea813589f25;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java
index 03dff75..4bd60cc 100644
--- a/src/main/java/net/pterodactylus/sone/data/Sone.java
+++ b/src/main/java/net/pterodactylus/sone/data/Sone.java
@@ -30,6 +30,7 @@ import java.util.logging.Logger;
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.template.SoneAccessor;
import net.pterodactylus.util.logging.Logging;
+import net.pterodactylus.util.validation.Validation;
import freenet.keys.FreenetURI;
/**
@@ -40,7 +41,7 @@ import freenet.keys.FreenetURI;
*
* @author David âBombeâ Roden
*/
-public class Sone implements Fingerprintable {
+public class Sone implements Fingerprintable, Comparable {
/** comparator that sorts Sones by their nice name. */
public static final Comparator NICE_NAME_COMPARATOR = new Comparator() {
@@ -99,6 +100,9 @@ public class Sone implements Fingerprintable {
/** The IDs of all liked replies. */
private final Set likedReplyIds = Collections.synchronizedSet(new HashSet());
+ /** The albums of this Sone. */
+ private final List albums = Collections.synchronizedList(new ArrayList());
+
/**
* Creates a new Sone.
*
@@ -176,7 +180,7 @@ public class Sone implements Fingerprintable {
*/
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)) {
@@ -204,7 +208,7 @@ public class Sone implements Fingerprintable {
*/
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)) {
@@ -580,6 +584,51 @@ public class Sone implements Fingerprintable {
return this;
}
+ /**
+ * Returns the albums of this Sone.
+ *
+ * @return The albums of this Sone
+ */
+ public List getAlbums() {
+ return Collections.unmodifiableList(albums);
+ }
+
+ /**
+ * Adds an album to this Sone.
+ *
+ * @param album
+ * The album to add
+ */
+ public synchronized void addAlbum(Album album) {
+ Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).check();
+ albums.add(album);
+ }
+
+ /**
+ * Sets the albums of this Sone.
+ *
+ * @param albums
+ * The albums of this Sone
+ */
+ public synchronized void setAlbums(Collection extends Album> albums) {
+ Validation.begin().isNotNull("Albums", albums).check();
+ albums.clear();
+ for (Album album : albums) {
+ addAlbum(album);
+ }
+ }
+
+ /**
+ * Removes an album from this Sone.
+ *
+ * @param album
+ * The album to remove
+ */
+ public synchronized void removeAlbum(Album album) {
+ Validation.begin().isNotNull("Album", album).check().isEqual("Album Owner", album.getSone(), this).check();
+ albums.remove(album);
+ }
+
//
// FINGERPRINTABLE METHODS
//
@@ -622,10 +671,28 @@ public class Sone implements Fingerprintable {
}
fingerprint.append(')');
+// fingerprint.append("Albums(");
+// for (Album album : albums) {
+// fingerprint.append(album.getFingerprint());
+// }
+// fingerprint.append(')');
+
return fingerprint.toString();
}
//
+ // INTERFACE Comparable
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int compareTo(Sone sone) {
+ return NICE_NAME_COMPARATOR.compare(this, sone);
+ }
+
+ //
// OBJECT METHODS
//