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