🔥 Remove function from Sone interface
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
1 /*
2  * Sone - Sone.java - Copyright Â© 2010–2020 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.data;
19
20 import static net.pterodactylus.sone.data.Album.FLATTENER;
21
22 import java.util.Collection;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.Set;
26
27 import javax.annotation.Nonnull;
28 import javax.annotation.Nullable;
29
30 import net.pterodactylus.sone.freenet.wot.Identity;
31
32 import freenet.keys.FreenetURI;
33
34 import com.google.common.base.Function;
35
36 /**
37  * A Sone defines everything about a user: her profile, her status updates, her
38  * replies, her likes and dislikes, etc.
39  */
40 public interface Sone extends Identified, Fingerprintable, Comparable<Sone> {
41
42         /**
43          * Enumeration for the possible states of a {@link Sone}.
44          */
45         public enum SoneStatus {
46
47                 /** The Sone is unknown, i.e. not yet downloaded. */
48                 unknown,
49
50                 /** The Sone is idle, i.e. not being downloaded or inserted. */
51                 idle,
52
53                 /** The Sone is currently being inserted. */
54                 inserting,
55
56                 /** The Sone is currently being downloaded. */
57                 downloading,
58         }
59
60         public static final Function<Sone, List<Album>> toAllAlbums = new Function<Sone, List<Album>>() {
61                 @Override
62                 public List<Album> apply(@Nullable Sone sone) {
63                         return (sone == null) ? Collections.<Album>emptyList() : FLATTENER.apply(
64                                         sone.getRootAlbum());
65                 }
66         };
67
68         /**
69          * Returns the identity of this Sone.
70          *
71          * @return The identity of this Sone
72          */
73         @Nonnull
74         Identity getIdentity();
75
76         /**
77          * Returns the name of this Sone.
78          *
79          * @return The name of this Sone
80          */
81         @Nonnull
82         String getName();
83
84         /**
85          * Returns whether this Sone is a local Sone.
86          *
87          * @return {@code true} if this Sone is a local Sone, {@code false} otherwise
88          */
89         boolean isLocal();
90
91         /**
92          * Returns the request URI of this Sone.
93          *
94          * @return The request URI of this Sone
95          */
96         @Nonnull
97         FreenetURI getRequestUri();
98
99         /**
100          * Returns the latest edition of this Sone.
101          *
102          * @return The latest edition of this Sone
103          */
104         long getLatestEdition();
105
106         /**
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
109          * not changed.
110          *
111          * @param latestEdition
112          *              The latest edition of this Sone
113          */
114         void setLatestEdition(long latestEdition);
115
116         /**
117          * Return the time of the last inserted update of this Sone.
118          *
119          * @return The time of the update (in milliseconds since Jan 1, 1970 UTC)
120          */
121         long getTime();
122
123         /**
124          * Sets the time of the last inserted update of this Sone.
125          *
126          * @param time
127          *              The time of the update (in milliseconds since Jan 1, 1970 UTC)
128          * @return This Sone (for method chaining)
129          */
130         @Nonnull
131         Sone setTime(long time);
132
133         /**
134          * Returns the status of this Sone.
135          *
136          * @return The status of this Sone
137          */
138         @Nonnull
139         SoneStatus getStatus();
140
141         /**
142          * Sets the new status of this Sone.
143          *
144          * @param status
145          *              The new status of this Sone
146          * @return This Sone
147          * @throws IllegalArgumentException
148          *              if {@code status} is {@code null}
149          */
150         @Nonnull
151         Sone setStatus(@Nonnull SoneStatus status);
152
153         /**
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.
157          *
158          * @return A copy of the profile
159          */
160         @Nonnull
161         Profile getProfile();
162
163         /**
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
166          * Sone!
167          *
168          * @param profile
169          *              The profile to set
170          */
171         void setProfile(@Nonnull Profile profile);
172
173         /**
174          * Returns the client used by this Sone.
175          *
176          * @return The client used by this Sone, or {@code null}
177          */
178         @Nullable
179         Client getClient();
180
181         /**
182          * Sets the client used by this Sone.
183          *
184          * @param client
185          *              The client used by this Sone, or {@code null}
186          * @return This Sone (for method chaining)
187          */
188         @Nonnull
189         Sone setClient(@Nullable Client client);
190
191         /**
192          * Returns whether this Sone is known.
193          *
194          * @return {@code true} if this Sone is known, {@code false} otherwise
195          */
196         boolean isKnown();
197
198         /**
199          * Sets whether this Sone is known.
200          *
201          * @param known
202          *              {@code true} if this Sone is known, {@code false} otherwise
203          * @return This Sone
204          */
205         @Nonnull
206         Sone setKnown(boolean known);
207
208         /**
209          * Returns all friend Sones of this Sone.
210          *
211          * @return The friend Sones of this Sone
212          */
213         @Nonnull
214         Collection<String> getFriends();
215
216         /**
217          * Returns whether this Sone has the given Sone as a friend Sone.
218          *
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
222          *         false} otherwise
223          */
224         boolean hasFriend(@Nonnull String friendSoneId);
225
226         /**
227          * Returns the list of posts of this Sone, sorted by time, newest first.
228          *
229          * @return All posts of this Sone
230          */
231         @Nonnull
232         List<Post> getPosts();
233
234         /**
235          * Sets all posts of this Sone at once.
236          *
237          * @param posts
238          *              The new (and only) posts of this Sone
239          * @return This Sone (for method chaining)
240          */
241         @Nonnull
242         Sone setPosts(@Nonnull Collection<Post> posts);
243
244         /**
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.
247          *
248          * @param post
249          *              The post to add
250          */
251         void addPost(@Nonnull Post post);
252
253         /**
254          * Removes the given post from this Sone.
255          *
256          * @param post
257          *              The post to remove
258          */
259         void removePost(@Nonnull Post post);
260
261         /**
262          * Returns all replies this Sone made.
263          *
264          * @return All replies this Sone made
265          */
266         @Nonnull
267         Set<PostReply> getReplies();
268
269         /**
270          * Sets all replies of this Sone at once.
271          *
272          * @param replies
273          *              The new (and only) replies of this Sone
274          * @return This Sone (for method chaining)
275          */
276         @Nonnull
277         Sone setReplies(@Nonnull Collection<PostReply> replies);
278
279         /**
280          * Adds a reply to this Sone. If the given reply was not made by this Sone,
281          * nothing is added to this Sone.
282          *
283          * @param reply
284          *              The reply to add
285          */
286         void addReply(@Nonnull PostReply reply);
287
288         /**
289          * Removes a reply from this Sone.
290          *
291          * @param reply
292          *              The reply to remove
293          */
294         void removeReply(@Nonnull PostReply reply);
295
296         /**
297          * Returns the IDs of all liked posts.
298          *
299          * @return All liked posts’ IDs
300          */
301         @Nonnull
302         Set<String> getLikedPostIds();
303
304         /**
305          * Sets the IDs of all liked posts.
306          *
307          * @param likedPostIds
308          *              All liked posts’ IDs
309          * @return This Sone (for method chaining)
310          */
311         @Nonnull
312         Sone setLikePostIds(@Nonnull Set<String> likedPostIds);
313
314         /**
315          * Checks whether the given post ID is liked by this Sone.
316          *
317          * @param postId
318          *              The ID of the post
319          * @return {@code true} if this Sone likes the given post, {@code false}
320          *         otherwise
321          */
322         boolean isLikedPostId(@Nonnull String postId);
323
324         /**
325          * Adds the given post ID to the list of posts this Sone likes.
326          *
327          * @param postId
328          *              The ID of the post
329          * @return This Sone (for method chaining)
330          */
331         @Nonnull
332         Sone addLikedPostId(@Nonnull String postId);
333
334         /**
335          * Removes the given post ID from the list of posts this Sone likes.
336          *
337          * @param postId
338          *              The ID of the post
339          */
340         void removeLikedPostId(@Nonnull String postId);
341
342         /**
343          * Returns the IDs of all liked replies.
344          *
345          * @return All liked replies’ IDs
346          */
347         @Nonnull
348         Set<String> getLikedReplyIds();
349
350         /**
351          * Sets the IDs of all liked replies.
352          *
353          * @param likedReplyIds
354          *              All liked replies’ IDs
355          * @return This Sone (for method chaining)
356          */
357         @Nonnull
358         Sone setLikeReplyIds(@Nonnull Set<String> likedReplyIds);
359
360         /**
361          * Checks whether the given reply ID is liked by this Sone.
362          *
363          * @param replyId
364          *              The ID of the reply
365          * @return {@code true} if this Sone likes the given reply, {@code false}
366          *         otherwise
367          */
368         boolean isLikedReplyId(@Nonnull String replyId);
369
370         /**
371          * Adds the given reply ID to the list of replies this Sone likes.
372          *
373          * @param replyId
374          *              The ID of the reply
375          * @return This Sone (for method chaining)
376          */
377         @Nonnull
378         Sone addLikedReplyId(@Nonnull String replyId);
379
380         /**
381          * Removes the given post ID from the list of replies this Sone likes.
382          *
383          * @param replyId
384          *              The ID of the reply
385          */
386         void removeLikedReplyId(@Nonnull String replyId);
387
388         /**
389          * Returns the root album that contains all visible albums of this Sone.
390          *
391          * @return The root album of this Sone
392          */
393         @Nonnull
394         Album getRootAlbum();
395
396         /**
397          * Returns Sone-specific options.
398          *
399          * @return The options of this Sone
400          */
401         @Nonnull
402         SoneOptions getOptions();
403
404         /**
405          * Sets the options of this Sone.
406          *
407          * @param options
408          *              The options of this Sone
409          */
410         /* TODO - remove this method again, maybe add an option provider */
411         void setOptions(@Nonnull SoneOptions options);
412
413 }