X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSone.java;h=bca789501669e16b84576861661fe7397e7abdb6;hb=0a4b6fc252003c71f4bdef09560e87982838d9c8;hp=41fdcc13a2f795ee654665d3f1fda1155d31490c;hpb=027615fa64c78ef5ebc198e852cfd6d39b18aad0;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 41fdcc1..bca7895 100644
--- a/src/main/java/net/pterodactylus/sone/data/Sone.java
+++ b/src/main/java/net/pterodactylus/sone/data/Sone.java
@@ -19,25 +19,31 @@ package net.pterodactylus.sone.data;
import static com.google.common.collect.FluentIterable.from;
import static java.util.Arrays.asList;
+import static net.pterodactylus.sone.core.SoneUri.create;
import static net.pterodactylus.sone.data.Album.FLATTENER;
import static net.pterodactylus.sone.data.Album.IMAGES;
+import static net.pterodactylus.sone.template.SoneAccessor.getNiceName;
import java.util.Collection;
+import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
+import javax.annotation.Nullable;
+
import net.pterodactylus.sone.core.Options;
-import net.pterodactylus.sone.database.AlbumBuilderFactory;
+import net.pterodactylus.sone.database.AlbumBuilder;
import net.pterodactylus.sone.database.PostBuilder;
-import net.pterodactylus.sone.database.PostBuilderFactory;
+import net.pterodactylus.sone.database.PostReplyBuilder;
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
-import net.pterodactylus.sone.template.SoneAccessor;
import freenet.keys.FreenetURI;
+import com.google.common.base.Function;
import com.google.common.base.Predicate;
+import com.google.common.collect.ComparisonChain;
import com.google.common.primitives.Ints;
/**
@@ -46,7 +52,7 @@ import com.google.common.primitives.Ints;
*
* @author David âBombeâ Roden
*/
-public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, AlbumBuilderFactory, Comparable {
+public interface Sone extends Identified, Fingerprintable, Comparable {
/**
* Enumeration for the possible states of a {@link Sone}.
@@ -97,15 +103,21 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, A
@Override
public int compare(Sone leftSone, Sone rightSone) {
- int diff = SoneAccessor.getNiceName(leftSone).compareToIgnoreCase(SoneAccessor.getNiceName(rightSone));
- if (diff != 0) {
- return diff;
- }
- return leftSone.getId().compareToIgnoreCase(rightSone.getId());
+ return ComparisonChain.start()
+ .compare(getNiceName(leftSone).toLowerCase(), getNiceName(rightSone).toLowerCase())
+ .compare(leftSone.getId(), rightSone.getId())
+ .result();
}
};
+ public static final Function TO_NICE_NAME = new Function() {
+ @Override
+ public String apply(Sone sone) {
+ return (sone == null) ? null : getNiceName(sone);
+ }
+ };
+
/** Comparator that sorts Sones by last activity (least recent active first). */
public static final Comparator LAST_ACTIVITY_COMPARATOR = new Comparator() {
@@ -156,7 +168,7 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, A
@Override
public boolean apply(Sone sone) {
- return (sone == null) ? false : sone.getIdentity() instanceof OwnIdentity;
+ return (sone == null) ? false : sone.isLocal();
}
};
@@ -170,6 +182,27 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, A
}
};
+ public static final Function TO_FREENET_URI = new Function() {
+ @Override
+ public FreenetURI apply(Sone sone) {
+ return (sone == null) ? null : create(sone.getIdentity().getRequestUri());
+ }
+ };
+
+ public static final Function TO_INSERT_URI = new Function() {
+ @Override
+ public FreenetURI apply(@Nullable Sone sone) {
+ return ((sone == null) || !sone.isLocal()) ? null : create(((OwnIdentity) sone.getIdentity()).getInsertUri());
+ }
+ };
+
+ public static final Function> TO_POSTS = new Function>() {
+ @Override
+ public List apply(Sone sone) {
+ return (sone == null) ? Collections.emptyList() : sone.getPosts();
+ }
+ };
+
/**
* Returns the identity of this Sone.
*
@@ -178,18 +211,6 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, A
Identity getIdentity();
/**
- * Sets the identity of this Sone. The {@link Identity#getId() ID} of the
- * identity has to match this Soneâs {@link #getId()}.
- *
- * @param identity
- * The identity of this Sone
- * @return This Sone (for method chaining)
- * @throws IllegalArgumentException
- * if the ID of the identity does not match this Soneâs ID
- */
- Sone setIdentity(Identity identity) throws IllegalArgumentException;
-
- /**
* Returns the name of this Sone.
*
* @return The name of this Sone
@@ -204,38 +225,6 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, A
boolean isLocal();
/**
- * Returns the request URI of this Sone.
- *
- * @return The request URI of this Sone
- */
- FreenetURI getRequestUri();
-
- /**
- * Sets the request URI of this Sone.
- *
- * @param requestUri
- * The request URI of this Sone
- * @return This Sone (for method chaining)
- */
- Sone setRequestUri(FreenetURI requestUri);
-
- /**
- * Returns the insert URI of this Sone.
- *
- * @return The insert URI of this Sone
- */
- FreenetURI getInsertUri();
-
- /**
- * Sets the insert URI of this Sone.
- *
- * @param insertUri
- * The insert URI of this Sone
- * @return This Sone (for method chaining)
- */
- Sone setInsertUri(FreenetURI insertUri);
-
- /**
* Returns the latest edition of this Sone.
*
* @return The latest edition of this Sone
@@ -243,16 +232,6 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, A
long getLatestEdition();
/**
- * Sets the latest edition of this Sone. If the given latest edition is not
- * greater than the current latest edition, the latest edition of this Sone is
- * not changed.
- *
- * @param latestEdition
- * The latest edition of this Sone
- */
- void setLatestEdition(long latestEdition);
-
- /**
* Return the time of the last inserted update of this Sone.
*
* @return The time of the update (in milliseconds since Jan 1, 1970 UTC)
@@ -313,15 +292,6 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, A
Client getClient();
/**
- * Sets the client used by this Sone.
- *
- * @param client
- * The client used by this Sone, or {@code null}
- * @return This Sone (for method chaining)
- */
- Sone setClient(Client client);
-
- /**
* Returns whether this Sone is known.
*
* @return {@code true} if this Sone is known, {@code false} otherwise
@@ -342,7 +312,7 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, A
*
* @return The friend Sones of this Sone
*/
- List getFriends();
+ Collection getFriends();
/**
* Returns whether this Sone has the given Sone as a friend Sone.
@@ -455,34 +425,6 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, A
Sone setLikePostIds(Set likedPostIds);
/**
- * Checks whether the given post ID is liked by this Sone.
- *
- * @param postId
- * The ID of the post
- * @return {@code true} if this Sone likes the given post, {@code false}
- * otherwise
- */
- boolean isLikedPostId(String postId);
-
- /**
- * Adds the given post ID to the list of posts this Sone likes.
- *
- * @param postId
- * The ID of the post
- * @return This Sone (for method chaining)
- */
- Sone addLikedPostId(String postId);
-
- /**
- * Removes the given post ID from the list of posts this Sone likes.
- *
- * @param postId
- * The ID of the post
- * @return This Sone (for method chaining)
- */
- Sone removeLikedPostId(String postId);
-
- /**
* Returns the IDs of all liked replies.
*
* @return All liked repliesâ IDs
@@ -499,34 +441,6 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, A
Sone setLikeReplyIds(Set likedReplyIds);
/**
- * Checks whether the given reply ID is liked by this Sone.
- *
- * @param replyId
- * The ID of the reply
- * @return {@code true} if this Sone likes the given reply, {@code false}
- * otherwise
- */
- boolean isLikedReplyId(String replyId);
-
- /**
- * Adds the given reply ID to the list of replies this Sone likes.
- *
- * @param replyId
- * The ID of the reply
- * @return This Sone (for method chaining)
- */
- Sone addLikedReplyId(String replyId);
-
- /**
- * Removes the given post ID from the list of replies this Sone likes.
- *
- * @param replyId
- * The ID of the reply
- * @return This Sone (for method chaining)
- */
- Sone removeLikedReplyId(String replyId);
-
- /**
* Returns the root album that contains all visible albums of this Sone.
*
* @return The root album of this Sone
@@ -549,6 +463,19 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, A
/* TODO - remove this method again, maybe add an option provider */
void setOptions(Options options);
+ AlbumBuilder newAlbumBuilder() throws IllegalStateException;
+
PostBuilder newPostBuilder();
+ PostReplyBuilder newPostReplyBuilder(String postId) throws IllegalStateException;
+
+ Modifier modify();
+
+ interface Modifier {
+
+ Modifier setLatestEdition(long latestEdition);
+ Sone update();
+
+ }
+
}