Clean up imports.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
index f1d9ffe..dfeb019 100644 (file)
@@ -19,10 +19,12 @@ 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 java.util.Collection;
+import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
 import java.util.Set;
@@ -30,13 +32,13 @@ import java.util.Set;
 import net.pterodactylus.sone.core.Options;
 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.primitives.Ints;
 
@@ -46,7 +48,7 @@ import com.google.common.primitives.Ints;
  *
  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
-public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, Comparable<Sone> {
+public interface Sone extends Identified, Fingerprintable, Comparable<Sone> {
 
        /**
         * Enumeration for the possible states of a {@link Sone}.
@@ -156,7 +158,7 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, C
 
                @Override
                public boolean apply(Sone sone) {
-                       return (sone == null) ? false : sone.getIdentity() instanceof OwnIdentity;
+                       return (sone == null) ? false : sone.isLocal();
                }
 
        };
@@ -170,6 +172,20 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, C
                }
        };
 
+       public static final Function<Sone, FreenetURI> TO_FREENET_URI = new Function<Sone, FreenetURI>() {
+               @Override
+               public FreenetURI apply(Sone sone) {
+                       return (sone == null) ? null : create(sone.getIdentity().getRequestUri());
+               }
+       };
+
+       public static final Function<Sone, List<Post>> TO_POSTS = new Function<Sone, List<Post>>() {
+               @Override
+               public List<Post> apply(Sone sone) {
+                       return (sone == null) ? Collections.<Post>emptyList() : sone.getPosts();
+               }
+       };
+
        /**
         * Returns the identity of this Sone.
         *
@@ -178,18 +194,6 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, C
        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 +208,6 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, C
        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 +215,6 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, C
        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 +275,6 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, C
        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 +295,7 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, C
         *
         * @return The friend Sones of this Sone
         */
-       List<String> getFriends();
+       Collection<String> getFriends();
 
        /**
         * Returns whether this Sone has the given Sone as a friend Sone.
@@ -553,4 +506,15 @@ public interface Sone extends Identified, Fingerprintable, PostBuilderFactory, C
 
        PostBuilder newPostBuilder();
 
+       PostReplyBuilder newPostReplyBuilder(String postId) throws IllegalStateException;
+
+       Modifier modify();
+
+       interface Modifier {
+
+               Modifier setLatestEdition(long latestEdition);
+               Sone update();
+
+       }
+
 }