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