}
};
+ /** Comparator that sorts Sones by number of images (descending). */
+ public static final Comparator<Sone> IMAGE_COUNT_COMPARATOR = new Comparator<Sone>() {
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int compare(Sone leftSone, Sone rightSone) {
+ return rightSone.getAllImages().size() - leftSone.getAllImages().size();
+ }
+ };
+
/** Filter to remove Sones that have not been downloaded. */
public static final Filter<Sone> EMPTY_SONE_FILTER = new Filter<Sone>() {
private final Set<Post> posts = Collections.synchronizedSet(new HashSet<Post>());
/** All replies. */
- private final Set<Reply> replies = Collections.synchronizedSet(new HashSet<Reply>());
+ private final Set<PostReply> replies = Collections.synchronizedSet(new HashSet<PostReply>());
/** The IDs of all liked posts. */
private final Set<String> likedPostIds = Collections.synchronizedSet(new HashSet<String>());
*
* @return All replies this Sone made
*/
- public synchronized Set<Reply> getReplies() {
+ public synchronized Set<PostReply> getReplies() {
return Collections.unmodifiableSet(replies);
}
* The new (and only) replies of this Sone
* @return This Sone (for method chaining)
*/
- public synchronized Sone setReplies(Collection<Reply> replies) {
+ public synchronized Sone setReplies(Collection<PostReply> replies) {
this.replies.clear();
this.replies.addAll(replies);
return this;
* @param reply
* The reply to add
*/
- public synchronized void addReply(Reply reply) {
+ public synchronized void addReply(PostReply reply) {
if (reply.getSone().equals(this)) {
replies.add(reply);
}
* @param reply
* The reply to remove
*/
- public synchronized void removeReply(Reply reply) {
+ public synchronized void removeReply(PostReply reply) {
if (reply.getSone().equals(this)) {
replies.remove(reply);
}
}
/**
+ * Returns all images of a Sone. Images of a album are inserted into this
+ * list before images of all child albums.
+ *
+ * @return The list of all images
+ */
+ public List<Image> getAllImages() {
+ List<Image> allImages = new ArrayList<Image>();
+ for (Album album : getAllAlbums()) {
+ allImages.addAll(album.getImages());
+ }
+ return allImages;
+ }
+
+ /**
* Adds an album to this Sone.
*
* @param album
}
fingerprint.append(")");
- List<Reply> replies = new ArrayList<Reply>(getReplies());
+ List<PostReply> replies = new ArrayList<PostReply>(getReplies());
Collections.sort(replies, Reply.TIME_COMPARATOR);
fingerprint.append("Replies(");
- for (Reply reply : replies) {
+ for (PostReply reply : replies) {
fingerprint.append("Reply(").append(reply.getId()).append(')');
}
fingerprint.append(')');