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