2 * Sone - Sone.java - Copyright © 2010–2020 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.data;
20 import static net.pterodactylus.sone.data.Album.FLATTENER;
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.List;
27 import javax.annotation.Nonnull;
28 import javax.annotation.Nullable;
30 import net.pterodactylus.sone.freenet.wot.Identity;
32 import freenet.keys.FreenetURI;
34 import com.google.common.base.Function;
37 * A Sone defines everything about a user: her profile, her status updates, her
38 * replies, her likes and dislikes, etc.
40 public interface Sone extends Identified, Fingerprintable, Comparable<Sone> {
43 * Enumeration for the possible states of a {@link Sone}.
45 public enum SoneStatus {
47 /** The Sone is unknown, i.e. not yet downloaded. */
50 /** The Sone is idle, i.e. not being downloaded or inserted. */
53 /** The Sone is currently being inserted. */
56 /** The Sone is currently being downloaded. */
60 public static final Function<Sone, List<Album>> toAllAlbums = new Function<Sone, List<Album>>() {
62 public List<Album> apply(@Nullable Sone sone) {
63 return (sone == null) ? Collections.<Album>emptyList() : FLATTENER.apply(
69 * Returns the identity of this Sone.
71 * @return The identity of this Sone
74 Identity getIdentity();
77 * Returns the name of this Sone.
79 * @return The name of this Sone
85 * Returns whether this Sone is a local Sone.
87 * @return {@code true} if this Sone is a local Sone, {@code false} otherwise
92 * Returns the request URI of this Sone.
94 * @return The request URI of this Sone
97 FreenetURI getRequestUri();
100 * Returns the latest edition of this Sone.
102 * @return The latest edition of this Sone
104 long getLatestEdition();
107 * Sets the latest edition of this Sone. If the given latest edition is not
108 * greater than the current latest edition, the latest edition of this Sone is
111 * @param latestEdition
112 * The latest edition of this Sone
114 void setLatestEdition(long latestEdition);
117 * Return the time of the last inserted update of this Sone.
119 * @return The time of the update (in milliseconds since Jan 1, 1970 UTC)
124 * Sets the time of the last inserted update of this Sone.
127 * The time of the update (in milliseconds since Jan 1, 1970 UTC)
128 * @return This Sone (for method chaining)
131 Sone setTime(long time);
134 * Returns the status of this Sone.
136 * @return The status of this Sone
139 SoneStatus getStatus();
142 * Sets the new status of this Sone.
145 * The new status of this Sone
147 * @throws IllegalArgumentException
148 * if {@code status} is {@code null}
151 Sone setStatus(@Nonnull SoneStatus status);
154 * Returns a copy of the profile. If you want to update values in the profile
155 * of this Sone, update the values in the returned {@link Profile} and use
156 * {@link #setProfile(Profile)} to change the profile in this Sone.
158 * @return A copy of the profile
161 Profile getProfile();
164 * Sets the profile of this Sone. A copy of the given profile is stored so that
165 * subsequent modifications of the given profile are not reflected in this
171 void setProfile(@Nonnull Profile profile);
174 * Returns the client used by this Sone.
176 * @return The client used by this Sone, or {@code null}
182 * Sets the client used by this Sone.
185 * The client used by this Sone, or {@code null}
186 * @return This Sone (for method chaining)
189 Sone setClient(@Nullable Client client);
192 * Returns whether this Sone is known.
194 * @return {@code true} if this Sone is known, {@code false} otherwise
199 * Sets whether this Sone is known.
202 * {@code true} if this Sone is known, {@code false} otherwise
206 Sone setKnown(boolean known);
209 * Returns all friend Sones of this Sone.
211 * @return The friend Sones of this Sone
214 Collection<String> getFriends();
217 * Returns whether this Sone has the given Sone as a friend Sone.
219 * @param friendSoneId
220 * The ID of the Sone to check for
221 * @return {@code true} if this Sone has the given Sone as a friend, {@code
224 boolean hasFriend(@Nonnull String friendSoneId);
227 * Returns the list of posts of this Sone, sorted by time, newest first.
229 * @return All posts of this Sone
232 List<Post> getPosts();
235 * Sets all posts of this Sone at once.
238 * The new (and only) posts of this Sone
239 * @return This Sone (for method chaining)
242 Sone setPosts(@Nonnull Collection<Post> posts);
245 * Adds the given post to this Sone. The post will not be added if its {@link
246 * Post#getSone() Sone} is not this Sone.
251 void addPost(@Nonnull Post post);
254 * Removes the given post from this Sone.
259 void removePost(@Nonnull Post post);
262 * Returns all replies this Sone made.
264 * @return All replies this Sone made
267 Set<PostReply> getReplies();
270 * Sets all replies of this Sone at once.
273 * The new (and only) replies of this Sone
274 * @return This Sone (for method chaining)
277 Sone setReplies(@Nonnull Collection<PostReply> replies);
280 * Adds a reply to this Sone. If the given reply was not made by this Sone,
281 * nothing is added to this Sone.
286 void addReply(@Nonnull PostReply reply);
289 * Removes a reply from this Sone.
292 * The reply to remove
294 void removeReply(@Nonnull PostReply reply);
297 * Returns the IDs of all liked posts.
299 * @return All liked posts’ IDs
302 Set<String> getLikedPostIds();
305 * Sets the IDs of all liked posts.
307 * @param likedPostIds
308 * All liked posts’ IDs
309 * @return This Sone (for method chaining)
312 Sone setLikePostIds(@Nonnull Set<String> likedPostIds);
315 * Checks whether the given post ID is liked by this Sone.
319 * @return {@code true} if this Sone likes the given post, {@code false}
322 boolean isLikedPostId(@Nonnull String postId);
325 * Adds the given post ID to the list of posts this Sone likes.
329 * @return This Sone (for method chaining)
332 Sone addLikedPostId(@Nonnull String postId);
335 * Removes the given post ID from the list of posts this Sone likes.
340 void removeLikedPostId(@Nonnull String postId);
343 * Returns the IDs of all liked replies.
345 * @return All liked replies’ IDs
348 Set<String> getLikedReplyIds();
351 * Sets the IDs of all liked replies.
353 * @param likedReplyIds
354 * All liked replies’ IDs
355 * @return This Sone (for method chaining)
358 Sone setLikeReplyIds(@Nonnull Set<String> likedReplyIds);
361 * Checks whether the given reply ID is liked by this Sone.
364 * The ID of the reply
365 * @return {@code true} if this Sone likes the given reply, {@code false}
368 boolean isLikedReplyId(@Nonnull String replyId);
371 * Adds the given reply ID to the list of replies this Sone likes.
374 * The ID of the reply
375 * @return This Sone (for method chaining)
378 Sone addLikedReplyId(@Nonnull String replyId);
381 * Removes the given post ID from the list of replies this Sone likes.
384 * The ID of the reply
386 void removeLikedReplyId(@Nonnull String replyId);
389 * Returns the root album that contains all visible albums of this Sone.
391 * @return The root album of this Sone
394 Album getRootAlbum();
397 * Returns Sone-specific options.
399 * @return The options of this Sone
402 SoneOptions getOptions();
405 * Sets the options of this Sone.
408 * The options of this Sone
410 /* TODO - remove this method again, maybe add an option provider */
411 void setOptions(@Nonnull SoneOptions options);