X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FSone.java;h=04c5f39b242ae56d517ebfdaeff1515175a761a3;hp=d7a7dee7b2d342c943983f96e295672227e91303;hb=0e8f7804ce344bdd69f5ecc7febe25a60a53561d;hpb=f4f5fb752ff9aff0235a907e170c6961576562f6 diff --git a/src/main/java/net/pterodactylus/sone/data/Sone.java b/src/main/java/net/pterodactylus/sone/data/Sone.java index d7a7dee..04c5f39 100644 --- a/src/main/java/net/pterodactylus/sone/data/Sone.java +++ b/src/main/java/net/pterodactylus/sone/data/Sone.java @@ -23,17 +23,21 @@ 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; -import net.pterodactylus.sone.core.Options; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + 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; @@ -144,7 +148,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { @Override public boolean apply(Sone sone) { - return (sone == null) ? false : sone.getTime() != 0; + return (sone != null) && (sone.getTime() != 0); } }; @@ -153,7 +157,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { @Override public boolean apply(Sone sone) { - return (sone == null) ? false : sone.getIdentity() instanceof OwnIdentity; + return (sone != null) && (sone.getIdentity() instanceof OwnIdentity); } }; @@ -163,7 +167,35 @@ public interface Sone extends Identified, Fingerprintable, Comparable { @Override public boolean apply(Sone sone) { - return (sone == null) ? false : !sone.getRootAlbum().getAlbums().isEmpty(); + return (sone != null) && !sone.getRootAlbum().getAlbums().isEmpty(); + } + }; + + public static final Function toSoneXmlUri = + new Function() { + @Nonnull + @Override + public String apply(@Nullable Sone input) { + return input.getRequestUri() + .setMetaString(new String[] { "sone.xml" }) + .toString(); + } + }; + + public static final Function> toAllAlbums = new Function>() { + @Override + public List apply(@Nullable Sone sone) { + return (sone == null) ? Collections.emptyList() : FLATTENER.apply( + sone.getRootAlbum()); + } + }; + + public static final Function> toAllImages = new Function>() { + @Override + public List apply(@Nullable Sone sone) { + return (sone == null) ? Collections.emptyList() : + from(FLATTENER.apply(sone.getRootAlbum())) + .transformAndConcat(IMAGES).toList(); } }; @@ -175,18 +207,6 @@ public interface Sone extends Identified, Fingerprintable, Comparable { 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 @@ -208,15 +228,6 @@ public interface Sone extends Identified, Fingerprintable, Comparable { 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 @@ -224,15 +235,6 @@ public interface Sone extends Identified, Fingerprintable, Comparable { 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 @@ -339,7 +341,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * * @return The friend Sones of this Sone */ - List getFriends(); + Collection getFriends(); /** * Returns whether this Sone has the given Sone as a friend Sone. @@ -352,24 +354,6 @@ public interface Sone extends Identified, Fingerprintable, Comparable { boolean hasFriend(String friendSoneId); /** - * Adds the given Sone as a friend Sone. - * - * @param friendSone - * The friend Sone to add - * @return This Sone (for method chaining) - */ - Sone addFriend(String friendSone); - - /** - * Removes the given Sone as a friend Sone. - * - * @param friendSoneId - * The ID of the friend Sone to remove - * @return This Sone (for method chaining) - */ - Sone removeFriend(String friendSoneId); - - /** * Returns the list of posts of this Sone, sorted by time, newest first. * * @return All posts of this Sone @@ -535,7 +519,7 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * * @return The options of this Sone */ - Options getOptions(); + SoneOptions getOptions(); /** * Sets the options of this Sone. @@ -544,6 +528,6 @@ public interface Sone extends Identified, Fingerprintable, Comparable { * The options of this Sone */ /* TODO - remove this method again, maybe add an option provider */ - void setOptions(Options options); + void setOptions(SoneOptions options); }