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