+ /**
+ * Sets the albums of this Sone.
+ *
+ * @param albums
+ * The albums of this Sone
+ */
+ public void setAlbums(Collection<? extends Album> albums) {
+ checkNotNull(albums, "albums must not be null");
+ this.albums.clear();
+ for (Album album : albums) {
+ addAlbum(album);
+ }
+ }
+
+ /**
+ * Removes an album from this Sone.
+ *
+ * @param album
+ * The album to remove
+ */
+ public void removeAlbum(Album album) {
+ checkNotNull(album, "album must not be null");
+ checkArgument(album.getSone().equals(this), "album must belong to this Sone");
+ albums.remove(album);
+ }
+
+ /**
+ * Moves the given album up in this album’s albums. If the album is already
+ * the first album, nothing happens.
+ *
+ * @param album
+ * The album to move up
+ * @return The album that the given album swapped the place with, or
+ * <code>null</code> if the album did not change its place
+ */
+ public Album moveAlbumUp(Album album) {
+ checkNotNull(album, "album must not be null");
+ checkArgument(album.getSone().equals(this), "album must belong to this Sone");
+ checkArgument(album.getParent() == null, "album must not have a parent");
+ int oldIndex = albums.indexOf(album);
+ if (oldIndex <= 0) {
+ return null;
+ }
+ albums.remove(oldIndex);
+ albums.add(oldIndex - 1, album);
+ return albums.get(oldIndex);
+ }
+
+ /**
+ * Moves the given album down in this album’s albums. If the album is
+ * already the last album, nothing happens.
+ *
+ * @param album
+ * The album to move down
+ * @return The album that the given album swapped the place with, or
+ * <code>null</code> if the album did not change its place
+ */
+ public Album moveAlbumDown(Album album) {
+ checkNotNull(album, "album must not be null");
+ checkArgument(album.getSone().equals(this), "album must belong to this Sone");
+ checkArgument(album.getParent() == null, "album must not have a parent");
+ int oldIndex = albums.indexOf(album);
+ if ((oldIndex < 0) || (oldIndex >= (albums.size() - 1))) {
+ return null;
+ }
+ albums.remove(oldIndex);
+ albums.add(oldIndex + 1, album);
+ return albums.get(oldIndex);
+ }
+
+ /**
+ * Returns Sone-specific options.
+ *
+ * @return The options of this Sone
+ */
+ public Options getOptions() {
+ return options;
+ }
+
+ /**
+ * Sets the options of this Sone.
+ *
+ * @param options
+ * The options of this Sone
+ */
+ /* TODO - remove this method again, maybe add an option provider */
+ public void setOptions(Options options) {
+ this.options = options;
+ }
+
+ //
+ // FINGERPRINTABLE METHODS
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public synchronized String getFingerprint() {
+ Hasher hash = Hashing.sha256().newHasher();
+ hash.putString(profile.getFingerprint());
+
+ hash.putString("Posts(");
+ for (Post post : getPosts()) {
+ hash.putString("Post(").putString(post.getId()).putString(")");
+ }
+ hash.putString(")");
+
+ List<PostReply> replies = new ArrayList<PostReply>(getReplies());
+ Collections.sort(replies, Reply.TIME_COMPARATOR);
+ hash.putString("Replies(");
+ for (PostReply reply : replies) {
+ hash.putString("Reply(").putString(reply.getId()).putString(")");
+ }
+ hash.putString(")");
+
+ List<String> likedPostIds = new ArrayList<String>(getLikedPostIds());
+ Collections.sort(likedPostIds);
+ hash.putString("LikedPosts(");
+ for (String likedPostId : likedPostIds) {
+ hash.putString("Post(").putString(likedPostId).putString(")");
+ }
+ hash.putString(")");
+
+ List<String> likedReplyIds = new ArrayList<String>(getLikedReplyIds());
+ Collections.sort(likedReplyIds);
+ hash.putString("LikedReplies(");
+ for (String likedReplyId : likedReplyIds) {
+ hash.putString("Reply(").putString(likedReplyId).putString(")");
+ }
+ hash.putString(")");
+
+ hash.putString("Albums(");
+ for (Album album : albums) {
+ hash.putString(album.getFingerprint());
+ }
+ hash.putString(")");
+
+ return hash.hash().toString();
+ }
+
+ //
+ // INTERFACE Comparable<Sone>
+ //
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int compareTo(Sone sone) {
+ return NICE_NAME_COMPARATOR.compare(this, sone);
+ }
+