1279f75f6b5fcb610730afdeb7c21d36afd93b65
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Sone.java
1 /*
2  * Sone - Sone.java - Copyright © 2010–2013 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.base.Preconditions.checkNotNull;
21 import static com.google.common.collect.FluentIterable.from;
22 import static java.util.Arrays.asList;
23 import static net.pterodactylus.sone.data.Album.FLATTENER;
24 import static net.pterodactylus.sone.data.Album.IMAGES;
25
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.Collections;
29 import java.util.Comparator;
30 import java.util.List;
31 import java.util.Set;
32 import java.util.concurrent.CopyOnWriteArraySet;
33 import java.util.logging.Level;
34 import java.util.logging.Logger;
35
36 import net.pterodactylus.sone.core.Options;
37 import net.pterodactylus.sone.freenet.wot.Identity;
38 import net.pterodactylus.sone.freenet.wot.OwnIdentity;
39 import net.pterodactylus.sone.template.SoneAccessor;
40 import net.pterodactylus.util.logging.Logging;
41
42 import freenet.keys.FreenetURI;
43
44 import com.google.common.base.Predicate;
45 import com.google.common.hash.Hasher;
46 import com.google.common.hash.Hashing;
47 import com.google.common.primitives.Ints;
48
49 /**
50  * A Sone defines everything about a user: her profile, her status updates, her
51  * replies, her likes and dislikes, etc.
52  * <p/>
53  * Operations that modify the Sone need to synchronize on the Sone in question.
54  *
55  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
56  */
57 public class Sone implements Identified, Fingerprintable, Comparable<Sone> {
58
59         /**
60          * Enumeration for the possible states of a {@link Sone}.
61          *
62          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
63          */
64         public enum SoneStatus {
65
66                 /** The Sone is unknown, i.e. not yet downloaded. */
67                 unknown,
68
69                 /** The Sone is idle, i.e. not being downloaded or inserted. */
70                 idle,
71
72                 /** The Sone is currently being inserted. */
73                 inserting,
74
75                 /** The Sone is currently being downloaded. */
76                 downloading,
77         }
78
79         /**
80          * The possible values for the “show custom avatars” option.
81          *
82          * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
83          */
84         public static enum ShowCustomAvatars {
85
86                 /** Never show custom avatars. */
87                 NEVER,
88
89                 /** Only show custom avatars of followed Sones. */
90                 FOLLOWED,
91
92                 /** Only show custom avatars of Sones you manually trust. */
93                 MANUALLY_TRUSTED,
94
95                 /** Only show custom avatars of automatically trusted Sones. */
96                 TRUSTED,
97
98                 /** Always show custom avatars. */
99                 ALWAYS,
100
101         }
102
103         /** comparator that sorts Sones by their nice name. */
104         public static final Comparator<Sone> NICE_NAME_COMPARATOR = new Comparator<Sone>() {
105
106                 @Override
107                 public int compare(Sone leftSone, Sone rightSone) {
108                         int diff = SoneAccessor.getNiceName(leftSone).compareToIgnoreCase(SoneAccessor.getNiceName(rightSone));
109                         if (diff != 0) {
110                                 return diff;
111                         }
112                         return leftSone.getId().compareToIgnoreCase(rightSone.getId());
113                 }
114
115         };
116
117         /** Comparator that sorts Sones by last activity (least recent active first). */
118         public static final Comparator<Sone> LAST_ACTIVITY_COMPARATOR = new Comparator<Sone>() {
119
120                 @Override
121                 public int compare(Sone firstSone, Sone secondSone) {
122                         return (int) Math.min(Integer.MAX_VALUE, Math.max(Integer.MIN_VALUE, secondSone.getTime() - firstSone.getTime()));
123                 }
124         };
125
126         /** Comparator that sorts Sones by numbers of posts (descending). */
127         public static final Comparator<Sone> POST_COUNT_COMPARATOR = new Comparator<Sone>() {
128
129                 /**
130                  * {@inheritDoc}
131                  */
132                 @Override
133                 public int compare(Sone leftSone, Sone rightSone) {
134                         return (leftSone.getPosts().size() != rightSone.getPosts().size()) ? (rightSone.getPosts().size() - leftSone.getPosts().size()) : (rightSone.getReplies().size() - leftSone.getReplies().size());
135                 }
136         };
137
138         /** Comparator that sorts Sones by number of images (descending). */
139         public static final Comparator<Sone> IMAGE_COUNT_COMPARATOR = new Comparator<Sone>() {
140
141                 /**
142                  * {@inheritDoc}
143                  */
144                 @Override
145                 public int compare(Sone leftSone, Sone rightSone) {
146                         int rightSoneImageCount = from(asList(rightSone.getRootAlbum())).transformAndConcat(FLATTENER).transformAndConcat(IMAGES).size();
147                         int leftSoneImageCount = from(asList(leftSone.getRootAlbum())).transformAndConcat(FLATTENER).transformAndConcat(IMAGES).size();
148                         /* sort descending. */
149                         return Ints.compare(rightSoneImageCount, leftSoneImageCount);
150                 }
151         };
152
153         /** Filter to remove Sones that have not been downloaded. */
154         public static final Predicate<Sone> EMPTY_SONE_FILTER = new Predicate<Sone>() {
155
156                 @Override
157                 public boolean apply(Sone sone) {
158                         return (sone == null) ? false : sone.getTime() != 0;
159                 }
160         };
161
162         /** Filter that matches all {@link Sone#isLocal() local Sones}. */
163         public static final Predicate<Sone> LOCAL_SONE_FILTER = new Predicate<Sone>() {
164
165                 @Override
166                 public boolean apply(Sone sone) {
167                         return (sone == null) ? false : sone.getIdentity() instanceof OwnIdentity;
168                 }
169
170         };
171
172         /** Filter that matches Sones that have at least one album. */
173         public static final Predicate<Sone> HAS_ALBUM_FILTER = new Predicate<Sone>() {
174
175                 @Override
176                 public boolean apply(Sone sone) {
177                         return (sone == null) ? false : !sone.getRootAlbum().getAlbums().isEmpty();
178                 }
179         };
180
181         /** The logger. */
182         private static final Logger logger = Logging.getLogger(Sone.class);
183
184         /** The ID of this Sone. */
185         private final String id;
186
187         /** Whether the Sone is local. */
188         private final boolean local;
189
190         /** The identity of this Sone. */
191         private Identity identity;
192
193         /** The URI under which the Sone is stored in Freenet. */
194         private volatile FreenetURI requestUri;
195
196         /** The URI used to insert a new version of this Sone. */
197         /* This will be null for remote Sones! */
198         private volatile FreenetURI insertUri;
199
200         /** The latest edition of the Sone. */
201         private volatile long latestEdition;
202
203         /** The time of the last inserted update. */
204         private volatile long time;
205
206         /** The status of this Sone. */
207         private volatile SoneStatus status = SoneStatus.unknown;
208
209         /** The profile of this Sone. */
210         private volatile Profile profile = new Profile(this);
211
212         /** The client used by the Sone. */
213         private volatile Client client;
214
215         /** Whether this Sone is known. */
216         private volatile boolean known;
217
218         /** All friend Sones. */
219         private final Set<String> friendSones = new CopyOnWriteArraySet<String>();
220
221         /** All posts. */
222         private final Set<Post> posts = new CopyOnWriteArraySet<Post>();
223
224         /** All replies. */
225         private final Set<PostReply> replies = new CopyOnWriteArraySet<PostReply>();
226
227         /** The IDs of all liked posts. */
228         private final Set<String> likedPostIds = new CopyOnWriteArraySet<String>();
229
230         /** The IDs of all liked replies. */
231         private final Set<String> likedReplyIds = new CopyOnWriteArraySet<String>();
232
233         /** The root album containing all albums. */
234         private final Album rootAlbum = new AlbumImpl().setSone(this);
235
236         /** Sone-specific options. */
237         private Options options = new Options();
238
239         /**
240          * Creates a new Sone.
241          *
242          * @param id
243          *              The ID of the Sone
244          * @param local
245          *              {@code true} if the Sone is a local Sone, {@code false} otherwise
246          */
247         public Sone(String id, boolean local) {
248                 this.id = id;
249                 this.local = local;
250         }
251
252         //
253         // ACCESSORS
254         //
255
256         /**
257          * Returns the identity of this Sone.
258          *
259          * @return The identity of this Sone
260          */
261         public String getId() {
262                 return id;
263         }
264
265         /**
266          * Returns the identity of this Sone.
267          *
268          * @return The identity of this Sone
269          */
270         public Identity getIdentity() {
271                 return identity;
272         }
273
274         /**
275          * Sets the identity of this Sone. The {@link Identity#getId() ID} of the
276          * identity has to match this Sone’s {@link #getId()}.
277          *
278          * @param identity
279          *              The identity of this Sone
280          * @return This Sone (for method chaining)
281          * @throws IllegalArgumentException
282          *              if the ID of the identity does not match this Sone’s ID
283          */
284         public Sone setIdentity(Identity identity) throws IllegalArgumentException {
285                 if (!identity.getId().equals(id)) {
286                         throw new IllegalArgumentException("Identity’s ID does not match Sone’s ID!");
287                 }
288                 this.identity = identity;
289                 return this;
290         }
291
292         /**
293          * Returns the name of this Sone.
294          *
295          * @return The name of this Sone
296          */
297         public String getName() {
298                 return (identity != null) ? identity.getNickname() : null;
299         }
300
301         /**
302          * Returns whether this Sone is a local Sone.
303          *
304          * @return {@code true} if this Sone is a local Sone, {@code false} otherwise
305          */
306         public boolean isLocal() {
307                 return local;
308         }
309
310         /**
311          * Returns the request URI of this Sone.
312          *
313          * @return The request URI of this Sone
314          */
315         public FreenetURI getRequestUri() {
316                 return (requestUri != null) ? requestUri.setSuggestedEdition(latestEdition) : null;
317         }
318
319         /**
320          * Sets the request URI of this Sone.
321          *
322          * @param requestUri
323          *              The request URI of this Sone
324          * @return This Sone (for method chaining)
325          */
326         public Sone setRequestUri(FreenetURI requestUri) {
327                 if (this.requestUri == null) {
328                         this.requestUri = requestUri.setKeyType("USK").setDocName("Sone").setMetaString(new String[0]);
329                         return this;
330                 }
331                 if (!this.requestUri.equalsKeypair(requestUri)) {
332                         logger.log(Level.WARNING, String.format("Request URI %s tried to overwrite %s!", requestUri, this.requestUri));
333                         return this;
334                 }
335                 return this;
336         }
337
338         /**
339          * Returns the insert URI of this Sone.
340          *
341          * @return The insert URI of this Sone
342          */
343         public FreenetURI getInsertUri() {
344                 return (insertUri != null) ? insertUri.setSuggestedEdition(latestEdition) : null;
345         }
346
347         /**
348          * Sets the insert URI of this Sone.
349          *
350          * @param insertUri
351          *              The insert URI of this Sone
352          * @return This Sone (for method chaining)
353          */
354         public Sone setInsertUri(FreenetURI insertUri) {
355                 if (this.insertUri == null) {
356                         this.insertUri = insertUri.setKeyType("USK").setDocName("Sone").setMetaString(new String[0]);
357                         return this;
358                 }
359                 if (!this.insertUri.equalsKeypair(insertUri)) {
360                         logger.log(Level.WARNING, String.format("Request URI %s tried to overwrite %s!", insertUri, this.insertUri));
361                         return this;
362                 }
363                 return this;
364         }
365
366         /**
367          * Returns the latest edition of this Sone.
368          *
369          * @return The latest edition of this Sone
370          */
371         public long getLatestEdition() {
372                 return latestEdition;
373         }
374
375         /**
376          * Sets the latest edition of this Sone. If the given latest edition is not
377          * greater than the current latest edition, the latest edition of this Sone is
378          * not changed.
379          *
380          * @param latestEdition
381          *              The latest edition of this Sone
382          */
383         public void setLatestEdition(long latestEdition) {
384                 if (!(latestEdition > this.latestEdition)) {
385                         logger.log(Level.FINE, String.format("New latest edition %d is not greater than current latest edition %d!", latestEdition, this.latestEdition));
386                         return;
387                 }
388                 this.latestEdition = latestEdition;
389         }
390
391         /**
392          * Return the time of the last inserted update of this Sone.
393          *
394          * @return The time of the update (in milliseconds since Jan 1, 1970 UTC)
395          */
396         public long getTime() {
397                 return time;
398         }
399
400         /**
401          * Sets the time of the last inserted update of this Sone.
402          *
403          * @param time
404          *              The time of the update (in milliseconds since Jan 1, 1970 UTC)
405          * @return This Sone (for method chaining)
406          */
407         public Sone setTime(long time) {
408                 this.time = time;
409                 return this;
410         }
411
412         /**
413          * Returns the status of this Sone.
414          *
415          * @return The status of this Sone
416          */
417         public SoneStatus getStatus() {
418                 return status;
419         }
420
421         /**
422          * Sets the new status of this Sone.
423          *
424          * @param status
425          *              The new status of this Sone
426          * @return This Sone
427          * @throws IllegalArgumentException
428          *              if {@code status} is {@code null}
429          */
430         public Sone setStatus(SoneStatus status) {
431                 this.status = checkNotNull(status, "status must not be null");
432                 return this;
433         }
434
435         /**
436          * Returns a copy of the profile. If you want to update values in the profile
437          * of this Sone, update the values in the returned {@link Profile} and use
438          * {@link #setProfile(Profile)} to change the profile in this Sone.
439          *
440          * @return A copy of the profile
441          */
442         public Profile getProfile() {
443                 return new Profile(profile);
444         }
445
446         /**
447          * Sets the profile of this Sone. A copy of the given profile is stored so that
448          * subsequent modifications of the given profile are not reflected in this
449          * Sone!
450          *
451          * @param profile
452          *              The profile to set
453          */
454         public void setProfile(Profile profile) {
455                 this.profile = new Profile(profile);
456         }
457
458         /**
459          * Returns the client used by this Sone.
460          *
461          * @return The client used by this Sone, or {@code null}
462          */
463         public Client getClient() {
464                 return client;
465         }
466
467         /**
468          * Sets the client used by this Sone.
469          *
470          * @param client
471          *              The client used by this Sone, or {@code null}
472          * @return This Sone (for method chaining)
473          */
474         public Sone setClient(Client client) {
475                 this.client = client;
476                 return this;
477         }
478
479         /**
480          * Returns whether this Sone is known.
481          *
482          * @return {@code true} if this Sone is known, {@code false} otherwise
483          */
484         public boolean isKnown() {
485                 return known;
486         }
487
488         /**
489          * Sets whether this Sone is known.
490          *
491          * @param known
492          *              {@code true} if this Sone is known, {@code false} otherwise
493          * @return This Sone
494          */
495         public Sone setKnown(boolean known) {
496                 this.known = known;
497                 return this;
498         }
499
500         /**
501          * Returns all friend Sones of this Sone.
502          *
503          * @return The friend Sones of this Sone
504          */
505         public List<String> getFriends() {
506                 List<String> friends = new ArrayList<String>(friendSones);
507                 return friends;
508         }
509
510         /**
511          * Returns whether this Sone has the given Sone as a friend Sone.
512          *
513          * @param friendSoneId
514          *              The ID of the Sone to check for
515          * @return {@code true} if this Sone has the given Sone as a friend, {@code
516          *         false} otherwise
517          */
518         public boolean hasFriend(String friendSoneId) {
519                 return friendSones.contains(friendSoneId);
520         }
521
522         /**
523          * Adds the given Sone as a friend Sone.
524          *
525          * @param friendSone
526          *              The friend Sone to add
527          * @return This Sone (for method chaining)
528          */
529         public Sone addFriend(String friendSone) {
530                 if (!friendSone.equals(id)) {
531                         friendSones.add(friendSone);
532                 }
533                 return this;
534         }
535
536         /**
537          * Removes the given Sone as a friend Sone.
538          *
539          * @param friendSoneId
540          *              The ID of the friend Sone to remove
541          * @return This Sone (for method chaining)
542          */
543         public Sone removeFriend(String friendSoneId) {
544                 friendSones.remove(friendSoneId);
545                 return this;
546         }
547
548         /**
549          * Returns the list of posts of this Sone, sorted by time, newest first.
550          *
551          * @return All posts of this Sone
552          */
553         public List<Post> getPosts() {
554                 List<Post> sortedPosts;
555                 synchronized (this) {
556                         sortedPosts = new ArrayList<Post>(posts);
557                 }
558                 Collections.sort(sortedPosts, Post.TIME_COMPARATOR);
559                 return sortedPosts;
560         }
561
562         /**
563          * Sets all posts of this Sone at once.
564          *
565          * @param posts
566          *              The new (and only) posts of this Sone
567          * @return This Sone (for method chaining)
568          */
569         public Sone setPosts(Collection<Post> posts) {
570                 synchronized (this) {
571                         this.posts.clear();
572                         this.posts.addAll(posts);
573                 }
574                 return this;
575         }
576
577         /**
578          * Adds the given post to this Sone. The post will not be added if its {@link
579          * Post#getSone() Sone} is not this Sone.
580          *
581          * @param post
582          *              The post to add
583          */
584         public void addPost(Post post) {
585                 if (post.getSone().equals(this) && posts.add(post)) {
586                         logger.log(Level.FINEST, String.format("Adding %s to “%s”.", post, getName()));
587                 }
588         }
589
590         /**
591          * Removes the given post from this Sone.
592          *
593          * @param post
594          *              The post to remove
595          */
596         public void removePost(Post post) {
597                 if (post.getSone().equals(this)) {
598                         posts.remove(post);
599                 }
600         }
601
602         /**
603          * Returns all replies this Sone made.
604          *
605          * @return All replies this Sone made
606          */
607         public Set<PostReply> getReplies() {
608                 return Collections.unmodifiableSet(replies);
609         }
610
611         /**
612          * Sets all replies of this Sone at once.
613          *
614          * @param replies
615          *              The new (and only) replies of this Sone
616          * @return This Sone (for method chaining)
617          */
618         public Sone setReplies(Collection<PostReply> replies) {
619                 this.replies.clear();
620                 this.replies.addAll(replies);
621                 return this;
622         }
623
624         /**
625          * Adds a reply to this Sone. If the given reply was not made by this Sone,
626          * nothing is added to this Sone.
627          *
628          * @param reply
629          *              The reply to add
630          */
631         public void addReply(PostReply reply) {
632                 if (reply.getSone().equals(this)) {
633                         replies.add(reply);
634                 }
635         }
636
637         /**
638          * Removes a reply from this Sone.
639          *
640          * @param reply
641          *              The reply to remove
642          */
643         public void removeReply(PostReply reply) {
644                 if (reply.getSone().equals(this)) {
645                         replies.remove(reply);
646                 }
647         }
648
649         /**
650          * Returns the IDs of all liked posts.
651          *
652          * @return All liked posts’ IDs
653          */
654         public Set<String> getLikedPostIds() {
655                 return Collections.unmodifiableSet(likedPostIds);
656         }
657
658         /**
659          * Sets the IDs of all liked posts.
660          *
661          * @param likedPostIds
662          *              All liked posts’ IDs
663          * @return This Sone (for method chaining)
664          */
665         public Sone setLikePostIds(Set<String> likedPostIds) {
666                 this.likedPostIds.clear();
667                 this.likedPostIds.addAll(likedPostIds);
668                 return this;
669         }
670
671         /**
672          * Checks whether the given post ID is liked by this Sone.
673          *
674          * @param postId
675          *              The ID of the post
676          * @return {@code true} if this Sone likes the given post, {@code false}
677          *         otherwise
678          */
679         public boolean isLikedPostId(String postId) {
680                 return likedPostIds.contains(postId);
681         }
682
683         /**
684          * Adds the given post ID to the list of posts this Sone likes.
685          *
686          * @param postId
687          *              The ID of the post
688          * @return This Sone (for method chaining)
689          */
690         public Sone addLikedPostId(String postId) {
691                 likedPostIds.add(postId);
692                 return this;
693         }
694
695         /**
696          * Removes the given post ID from the list of posts this Sone likes.
697          *
698          * @param postId
699          *              The ID of the post
700          * @return This Sone (for method chaining)
701          */
702         public Sone removeLikedPostId(String postId) {
703                 likedPostIds.remove(postId);
704                 return this;
705         }
706
707         /**
708          * Returns the IDs of all liked replies.
709          *
710          * @return All liked replies’ IDs
711          */
712         public Set<String> getLikedReplyIds() {
713                 return Collections.unmodifiableSet(likedReplyIds);
714         }
715
716         /**
717          * Sets the IDs of all liked replies.
718          *
719          * @param likedReplyIds
720          *              All liked replies’ IDs
721          * @return This Sone (for method chaining)
722          */
723         public Sone setLikeReplyIds(Set<String> likedReplyIds) {
724                 this.likedReplyIds.clear();
725                 this.likedReplyIds.addAll(likedReplyIds);
726                 return this;
727         }
728
729         /**
730          * Checks whether the given reply ID is liked by this Sone.
731          *
732          * @param replyId
733          *              The ID of the reply
734          * @return {@code true} if this Sone likes the given reply, {@code false}
735          *         otherwise
736          */
737         public boolean isLikedReplyId(String replyId) {
738                 return likedReplyIds.contains(replyId);
739         }
740
741         /**
742          * Adds the given reply ID to the list of replies this Sone likes.
743          *
744          * @param replyId
745          *              The ID of the reply
746          * @return This Sone (for method chaining)
747          */
748         public Sone addLikedReplyId(String replyId) {
749                 likedReplyIds.add(replyId);
750                 return this;
751         }
752
753         /**
754          * Removes the given post ID from the list of replies this Sone likes.
755          *
756          * @param replyId
757          *              The ID of the reply
758          * @return This Sone (for method chaining)
759          */
760         public Sone removeLikedReplyId(String replyId) {
761                 likedReplyIds.remove(replyId);
762                 return this;
763         }
764
765         /**
766          * Returns the root album that contains all visible albums of this Sone.
767          *
768          * @return The root album of this Sone
769          */
770         public Album getRootAlbum() {
771                 return rootAlbum;
772         }
773
774         /**
775          * Returns Sone-specific options.
776          *
777          * @return The options of this Sone
778          */
779         public Options getOptions() {
780                 return options;
781         }
782
783         /**
784          * Sets the options of this Sone.
785          *
786          * @param options
787          *              The options of this Sone
788          */
789         /* TODO - remove this method again, maybe add an option provider */
790         public void setOptions(Options options) {
791                 this.options = options;
792         }
793
794         //
795         // FINGERPRINTABLE METHODS
796         //
797
798         /** {@inheritDoc} */
799         @Override
800         public synchronized String getFingerprint() {
801                 Hasher hash = Hashing.sha256().newHasher();
802                 hash.putString(profile.getFingerprint());
803
804                 hash.putString("Posts(");
805                 for (Post post : getPosts()) {
806                         hash.putString("Post(").putString(post.getId()).putString(")");
807                 }
808                 hash.putString(")");
809
810                 List<PostReply> replies = new ArrayList<PostReply>(getReplies());
811                 Collections.sort(replies, Reply.TIME_COMPARATOR);
812                 hash.putString("Replies(");
813                 for (PostReply reply : replies) {
814                         hash.putString("Reply(").putString(reply.getId()).putString(")");
815                 }
816                 hash.putString(")");
817
818                 List<String> likedPostIds = new ArrayList<String>(getLikedPostIds());
819                 Collections.sort(likedPostIds);
820                 hash.putString("LikedPosts(");
821                 for (String likedPostId : likedPostIds) {
822                         hash.putString("Post(").putString(likedPostId).putString(")");
823                 }
824                 hash.putString(")");
825
826                 List<String> likedReplyIds = new ArrayList<String>(getLikedReplyIds());
827                 Collections.sort(likedReplyIds);
828                 hash.putString("LikedReplies(");
829                 for (String likedReplyId : likedReplyIds) {
830                         hash.putString("Reply(").putString(likedReplyId).putString(")");
831                 }
832                 hash.putString(")");
833
834                 hash.putString("Albums(");
835                 for (Album album : rootAlbum.getAlbums()) {
836                         if (!Album.NOT_EMPTY.apply(album)) {
837                                 continue;
838                         }
839                         hash.putString(album.getFingerprint());
840                 }
841                 hash.putString(")");
842
843                 return hash.hash().toString();
844         }
845
846         //
847         // INTERFACE Comparable<Sone>
848         //
849
850         /** {@inheritDoc} */
851         @Override
852         public int compareTo(Sone sone) {
853                 return NICE_NAME_COMPARATOR.compare(this, sone);
854         }
855
856         //
857         // OBJECT METHODS
858         //
859
860         /** {@inheritDoc} */
861         @Override
862         public int hashCode() {
863                 return id.hashCode();
864         }
865
866         /** {@inheritDoc} */
867         @Override
868         public boolean equals(Object object) {
869                 if (!(object instanceof Sone)) {
870                         return false;
871                 }
872                 return ((Sone) object).id.equals(id);
873         }
874
875         /** {@inheritDoc} */
876         @Override
877         public String toString() {
878                 return getClass().getName() + "[identity=" + identity + ",requestUri=" + requestUri + ",insertUri(" + String.valueOf(insertUri).length() + "),friends(" + friendSones.size() + "),posts(" + posts.size() + "),replies(" + replies.size() + "),albums(" + getRootAlbum().getAlbums().size() + ")]";
879         }
880
881 }