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