import java.util.Comparator;
-import net.pterodactylus.util.collection.filter.Filter;
+import com.google.common.base.Predicate;
/**
* A post is a short message that a user writes in his Sone to let other users
};
/** Filter for posts with timestamps from the future. */
- public static final Filter<Post> FUTURE_POSTS_FILTER = new Filter<Post>() {
+ public static final Predicate<Post> FUTURE_POSTS_FILTER = new Predicate<Post>() {
@Override
- public boolean filterObject(Post post) {
+ public boolean apply(Post post) {
return post.getTime() <= System.currentTimeMillis();
}
import java.util.Comparator;
import java.util.UUID;
-import net.pterodactylus.util.collection.filter.Filter;
+import com.google.common.base.Predicate;
/**
* Abstract base class for all replies.
};
/** Filter for replies with timestamps from the future. */
- public static final Filter<Reply<?>> FUTURE_REPLY_FILTER = new Filter<Reply<?>>() {
+ public static final Predicate<Reply<?>> FUTURE_REPLY_FILTER = new Predicate<Reply<?>>() {
/**
* {@inheritDoc}
*/
@Override
- public boolean filterObject(Reply<?> reply) {
+ public boolean apply(Reply<?> reply) {
return reply.getTime() <= System.currentTimeMillis();
}
import net.pterodactylus.sone.freenet.wot.Identity;
import net.pterodactylus.sone.freenet.wot.OwnIdentity;
import net.pterodactylus.sone.template.SoneAccessor;
-import net.pterodactylus.util.collection.filter.Filter;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.validation.Validation;
+
+import com.google.common.base.Predicate;
+
import freenet.keys.FreenetURI;
/**
};
/** Filter to remove Sones that have not been downloaded. */
- public static final Filter<Sone> EMPTY_SONE_FILTER = new Filter<Sone>() {
+ public static final Predicate<Sone> EMPTY_SONE_FILTER = new Predicate<Sone>() {
@Override
- public boolean filterObject(Sone sone) {
+ public boolean apply(Sone sone) {
return sone.getTime() != 0;
}
};
/** Filter that matches all {@link Sone#isLocal() local Sones}. */
- public static final Filter<Sone> LOCAL_SONE_FILTER = new Filter<Sone>() {
+ public static final Predicate<Sone> LOCAL_SONE_FILTER = new Predicate<Sone>() {
@Override
- public boolean filterObject(Sone sone) {
+ public boolean apply(Sone sone) {
return sone.getIdentity() instanceof OwnIdentity;
}
};
/** Filter that matches Sones that have at least one album. */
- public static final Filter<Sone> HAS_ALBUM_FILTER = new Filter<Sone>() {
+ public static final Predicate<Sone> HAS_ALBUM_FILTER = new Predicate<Sone>() {
@Override
- public boolean filterObject(Sone sone) {
+ public boolean apply(Sone sone) {
return !sone.getAlbums().isEmpty();
}
};
import net.pterodactylus.sone.freenet.fcp.Command;
import net.pterodactylus.sone.freenet.fcp.FcpException;
import net.pterodactylus.sone.template.SoneAccessor;
-import net.pterodactylus.util.collection.filter.Filters;
+
+import com.google.common.collect.Collections2;
+
import freenet.node.FSParseException;
import freenet.support.SimpleFieldSet;
String postPrefix = prefix + postIndex++;
postBuilder.put(encodePost(post, postPrefix + ".", includeReplies));
if (includeReplies) {
- postBuilder.put(encodeReplies(Filters.filteredList(core.getReplies(post), Reply.FUTURE_REPLY_FILTER), postPrefix + "."));
+ postBuilder.put(encodeReplies(Collections2.filter(core.getReplies(post), Reply.FUTURE_REPLY_FILTER), postPrefix + "."));
}
}
package net.pterodactylus.sone.fcp;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import net.pterodactylus.sone.core.Core;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.freenet.fcp.FcpException;
-import net.pterodactylus.util.collection.filter.Filters;
+
+import com.google.common.collect.Collections2;
+
import freenet.support.SimpleFieldSet;
import freenet.support.api.Bucket;
int startPost = getInt(parameters, "StartPost", 0);
int maxPosts = getInt(parameters, "MaxPosts", -1);
- Set<Post> allPosts = new HashSet<Post>();
+ Collection<Post> allPosts = new HashSet<Post>();
allPosts.addAll(sone.getPosts());
for (String friendSoneId : sone.getFriends()) {
if (!getCore().hasSone(friendSoneId)) {
allPosts.addAll(getCore().getSone(friendSoneId, false).getPosts());
}
allPosts.addAll(getCore().getDirectedPosts(sone));
- allPosts = Filters.filteredSet(allPosts, Post.FUTURE_POSTS_FILTER);
+ allPosts = Collections2.filter(allPosts, Post.FUTURE_POSTS_FILTER);
List<Post> sortedPosts = new ArrayList<Post>(allPosts);
Collections.sort(sortedPosts, Post.TIME_COMPARATOR);
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.data.Reply;
import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.util.collection.filter.Filters;
import net.pterodactylus.util.template.ReflectionAccessor;
import net.pterodactylus.util.template.TemplateContext;
+import com.google.common.collect.Collections2;
+
/**
* Accessor for {@link Post} objects that adds additional properties:
* <dl>
public Object get(TemplateContext templateContext, Object object, String member) {
Post post = (Post) object;
if ("replies".equals(member)) {
- return Filters.filteredList(core.getReplies(post), Reply.FUTURE_REPLY_FILTER);
+ return Collections2.filter(core.getReplies(post), Reply.FUTURE_REPLY_FILTER);
} else if (member.equals("likes")) {
return core.getLikes(post);
} else if (member.equals("liked")) {
package net.pterodactylus.sone.web;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import net.pterodactylus.sone.data.Post;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.collection.Pagination;
-import net.pterodactylus.util.collection.filter.Filter;
-import net.pterodactylus.util.collection.filter.Filters;
import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+
/**
* Page that lets the user browse all his bookmarked posts.
*
protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
super.processTemplate(request, templateContext);
Set<Post> allPosts = webInterface.getCore().getBookmarkedPosts();
- Set<Post> loadedPosts = Filters.filteredSet(allPosts, new Filter<Post>() {
+ Collection<Post> loadedPosts = Collections2.filter(allPosts, new Predicate<Post>() {
@Override
- public boolean filterObject(Post post) {
+ public boolean apply(Post post) {
return post.getSone() != null;
}
});
package net.pterodactylus.sone.web;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import net.pterodactylus.sone.notify.ListNotificationFilters;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.collection.Pagination;
-import net.pterodactylus.util.collection.filter.Filter;
-import net.pterodactylus.util.collection.filter.Filters;
import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+
/**
* The index page shows the main page of Sone. This page will contain the posts
* of all friends of the current user.
protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
super.processTemplate(request, templateContext);
final Sone currentSone = getCurrentSone(request.getToadletContext());
- List<Post> allPosts = new ArrayList<Post>();
+ Collection<Post> allPosts = new ArrayList<Post>();
allPosts.addAll(currentSone.getPosts());
for (String friendSoneId : currentSone.getFriends()) {
if (!webInterface.getCore().hasSone(friendSoneId)) {
}
}
}
- allPosts = Filters.filteredList(allPosts, new Filter<Post>() {
+ allPosts = Collections2.filter(allPosts, new Predicate<Post>() {
@Override
- public boolean filterObject(Post post) {
+ public boolean apply(Post post) {
return ListNotificationFilters.isPostVisible(currentSone, post);
}
});
- allPosts = Filters.filteredList(allPosts, Post.FUTURE_POSTS_FILTER);
- Collections.sort(allPosts, Post.TIME_COMPARATOR);
- Pagination<Post> pagination = new Pagination<Post>(allPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
+ allPosts = Collections2.filter(allPosts, Post.FUTURE_POSTS_FILTER);
+ List<Post> sortedPosts = new ArrayList<Post>(allPosts);
+ Collections.sort(sortedPosts, Post.TIME_COMPARATOR);
+ Pagination<Post> pagination = new Pagination<Post>(sortedPosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
templateContext.set("pagination", pagination);
templateContext.set("posts", pagination.getItems());
}
package net.pterodactylus.sone.web;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.List;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.collection.Pagination;
import net.pterodactylus.util.collection.ReverseComparator;
-import net.pterodactylus.util.collection.filter.Filter;
-import net.pterodactylus.util.collection.filter.Filters;
import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import com.google.common.base.Predicate;
+import com.google.common.base.Predicates;
+import com.google.common.collect.Collections2;
+
/**
* This page shows all known Sones.
*
templateContext.set("order", (sortOrder != null) ? sortOrder : "asc");
templateContext.set("filter", filter);
final Sone currentSone = getCurrentSone(request.getToadletContext(), false);
- List<Sone> knownSones = Filters.filteredList(new ArrayList<Sone>(webInterface.getCore().getSones()), Sone.EMPTY_SONE_FILTER);
+ Collection<Sone> knownSones = Collections2.filter(webInterface.getCore().getSones(), Sone.EMPTY_SONE_FILTER);
if ((currentSone != null) && "followed".equals(filter)) {
- knownSones = Filters.filteredList(knownSones, new Filter<Sone>() {
+ knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
@Override
- public boolean filterObject(Sone sone) {
+ public boolean apply(Sone sone) {
return currentSone.hasFriend(sone.getId());
}
});
} else if ((currentSone != null) && "not-followed".equals(filter)) {
- knownSones = Filters.filteredList(knownSones, new Filter<Sone>() {
+ knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
@Override
- public boolean filterObject(Sone sone) {
+ public boolean apply(Sone sone) {
return !currentSone.hasFriend(sone.getId());
}
});
} else if ("new".equals(filter)) {
- knownSones = Filters.filteredList(knownSones, new Filter<Sone>() {
+ knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
+
/**
* {@inheritDoc}
*/
@Override
- public boolean filterObject(Sone sone) {
+ public boolean apply(Sone sone) {
return !sone.isKnown();
}
});
} else if ("not-new".equals(filter)) {
- knownSones = Filters.filteredList(knownSones, new Filter<Sone>() {
+ knownSones = Collections2.filter(knownSones, new Predicate<Sone>() {
+
/**
* {@inheritDoc}
*/
@Override
- public boolean filterObject(Sone sone) {
+ public boolean apply(Sone sone) {
return sone.isKnown();
}
});
} else if ("own".equals(filter)) {
- knownSones = Filters.filteredList(knownSones, Sone.LOCAL_SONE_FILTER);
+ knownSones = Collections2.filter(knownSones, Sone.LOCAL_SONE_FILTER);
} else if ("not-own".equals(filter)) {
- knownSones = Filters.filteredList(knownSones, Filters.reverseFilter(Sone.LOCAL_SONE_FILTER));
+ knownSones = Collections2.filter(knownSones, Predicates.not(Sone.LOCAL_SONE_FILTER));
}
+ List<Sone> sortedSones = new ArrayList<Sone>(knownSones);
if ("activity".equals(sortField)) {
if ("asc".equals(sortOrder)) {
- Collections.sort(knownSones, new ReverseComparator<Sone>(Sone.LAST_ACTIVITY_COMPARATOR));
+ Collections.sort(sortedSones, new ReverseComparator<Sone>(Sone.LAST_ACTIVITY_COMPARATOR));
} else {
- Collections.sort(knownSones, Sone.LAST_ACTIVITY_COMPARATOR);
+ Collections.sort(sortedSones, Sone.LAST_ACTIVITY_COMPARATOR);
}
} else if ("posts".equals(sortField)) {
if ("asc".equals(sortOrder)) {
- Collections.sort(knownSones, new ReverseComparator<Sone>(Sone.POST_COUNT_COMPARATOR));
+ Collections.sort(sortedSones, new ReverseComparator<Sone>(Sone.POST_COUNT_COMPARATOR));
} else {
- Collections.sort(knownSones, Sone.POST_COUNT_COMPARATOR);
+ Collections.sort(sortedSones, Sone.POST_COUNT_COMPARATOR);
}
} else if ("images".equals(sortField)) {
if ("asc".equals(sortOrder)) {
- Collections.sort(knownSones, new ReverseComparator<Sone>(Sone.IMAGE_COUNT_COMPARATOR));
+ Collections.sort(sortedSones, new ReverseComparator<Sone>(Sone.IMAGE_COUNT_COMPARATOR));
} else {
- Collections.sort(knownSones, Sone.IMAGE_COUNT_COMPARATOR);
+ Collections.sort(sortedSones, Sone.IMAGE_COUNT_COMPARATOR);
}
} else {
if ("desc".equals(sortOrder)) {
- Collections.sort(knownSones, new ReverseComparator<Sone>(Sone.NICE_NAME_COMPARATOR));
+ Collections.sort(sortedSones, new ReverseComparator<Sone>(Sone.NICE_NAME_COMPARATOR));
} else {
- Collections.sort(knownSones, Sone.NICE_NAME_COMPARATOR);
+ Collections.sort(sortedSones, Sone.NICE_NAME_COMPARATOR);
}
}
- Pagination<Sone> sonePagination = new Pagination<Sone>(knownSones, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
+ Pagination<Sone> sonePagination = new Pagination<Sone>(sortedSones, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
templateContext.set("pagination", sonePagination);
templateContext.set("knownSones", sonePagination.getItems());
}
import net.pterodactylus.util.cache.ValueRetriever;
import net.pterodactylus.util.collection.Pagination;
import net.pterodactylus.util.collection.TimedMap;
-import net.pterodactylus.util.collection.filter.Filter;
-import net.pterodactylus.util.collection.filter.Filters;
import net.pterodactylus.util.collection.mapper.Mapper;
import net.pterodactylus.util.collection.mapper.Mappers;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.text.StringEscaper;
import net.pterodactylus.util.text.TextException;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+
/**
* This page lets the user search for posts and replies that contain certain
* words.
for (Sone sone : webInterface.getCore().getSones()) {
posts.addAll(sone.getPosts());
}
- return new DefaultCacheItem<Set<Hit<Post>>>(getHits(Filters.filteredSet(posts, Post.FUTURE_POSTS_FILTER), phrases, new PostStringGenerator()));
+ return new DefaultCacheItem<Set<Hit<Post>>>(getHits(Collections2.filter(posts, Post.FUTURE_POSTS_FILTER), phrases, new PostStringGenerator()));
}
}, new TimedMap<List<Phrase>, CacheItem<Set<Hit<Post>>>>(300000));
}
Set<Sone> sones = webInterface.getCore().getSones();
- Set<Hit<Sone>> soneHits = getHits(sones, phrases, SoneStringGenerator.COMPLETE_GENERATOR);
+ Collection<Hit<Sone>> soneHits = getHits(sones, phrases, SoneStringGenerator.COMPLETE_GENERATOR);
- Set<Hit<Post>> postHits;
+ Collection<Hit<Post>> postHits;
try {
postHits = hitCache.get(phrases);
} catch (CacheException ce1) {
}
/* now filter. */
- soneHits = Filters.filteredSet(soneHits, Hit.POSITIVE_FILTER);
- postHits = Filters.filteredSet(postHits, Hit.POSITIVE_FILTER);
+ soneHits = Collections2.filter(soneHits, Hit.POSITIVE_FILTER);
+ postHits = Collections2.filter(postHits, Hit.POSITIVE_FILTER);
/* now sort. */
List<Hit<Sone>> sortedSoneHits = new ArrayList<Hit<Sone>>(soneHits);
if (post.getRecipient() != null) {
postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(post.getRecipient()));
}
- for (PostReply reply : Filters.filteredList(webInterface.getCore().getReplies(post), Reply.FUTURE_REPLY_FILTER)) {
+ for (PostReply reply : Collections2.filter(webInterface.getCore().getReplies(post), Reply.FUTURE_REPLY_FILTER)) {
postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(reply.getSone()));
postString.append(' ').append(reply.getText());
}
private static class Hit<T> {
/** Filter for {@link Hit}s with a score of more than 0. */
- public static final Filter<Hit<?>> POSITIVE_FILTER = new Filter<Hit<?>>() {
+ public static final Predicate<Hit<?>> POSITIVE_FILTER = new Predicate<Hit<?>>() {
@Override
- public boolean filterObject(Hit<?> hit) {
+ public boolean apply(Hit<?> hit) {
return hit.getScore() > 0;
}
import net.pterodactylus.sone.web.page.PageToadlet;
import net.pterodactylus.sone.web.page.PageToadletFactory;
import net.pterodactylus.util.collection.SetBuilder;
-import net.pterodactylus.util.collection.filter.Filters;
import net.pterodactylus.util.logging.Logging;
import net.pterodactylus.util.notify.Notification;
import net.pterodactylus.util.notify.NotificationManager;
import net.pterodactylus.util.web.StaticPage;
import net.pterodactylus.util.web.TemplatePage;
+import com.google.common.collect.Collections2;
import com.google.inject.Inject;
import freenet.clients.http.SessionManager;
* The text to parse
* @return All mentioned local Sones
*/
- private Set<Sone> getMentionedSones(String text) {
+ private Collection<Sone> getMentionedSones(String text) {
/* we need no context to find mentioned Sones. */
Set<Sone> mentionedSones = new HashSet<Sone>();
try {
} catch (IOException ioe1) {
logger.log(Level.WARNING, String.format("Could not parse post text: %s", text), ioe1);
}
- return Filters.filteredSet(mentionedSones, Sone.LOCAL_SONE_FILTER);
+ return Collections2.filter(mentionedSones, Sone.LOCAL_SONE_FILTER);
}
/**
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import net.pterodactylus.sone.template.SoneAccessor;
import net.pterodactylus.sone.web.WebInterface;
import net.pterodactylus.sone.web.page.FreenetRequest;
-import net.pterodactylus.util.collection.filter.Filter;
-import net.pterodactylus.util.collection.filter.Filters;
import net.pterodactylus.util.json.JsonArray;
import net.pterodactylus.util.json.JsonObject;
import net.pterodactylus.util.notify.Notification;
import net.pterodactylus.util.object.HashCode;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+
/**
* The “get status” AJAX handler returns all information that is necessary to
* update the web interface in real-time.
Collections.sort(notifications, Notification.CREATED_TIME_SORTER);
int notificationHash = HashCode.hashCode(notifications);
/* load new posts. */
- Set<Post> newPosts = webInterface.getNewPosts();
+ Collection<Post> newPosts = webInterface.getNewPosts();
if (currentSone != null) {
- newPosts = Filters.filteredSet(newPosts, new Filter<Post>() {
+ newPosts = Collections2.filter(newPosts, new Predicate<Post>() {
@Override
- public boolean filterObject(Post post) {
+ public boolean apply(Post post) {
return ListNotificationFilters.isPostVisible(currentSone, post);
}
jsonPosts.add(jsonPost);
}
/* load new replies. */
- Set<PostReply> newReplies = webInterface.getNewReplies();
+ Collection<PostReply> newReplies = webInterface.getNewReplies();
if (currentSone != null) {
- newReplies = Filters.filteredSet(newReplies, new Filter<PostReply>() {
+ newReplies = Collections2.filter(newReplies, new Predicate<PostReply>() {
@Override
- public boolean filterObject(PostReply reply) {
+ public boolean apply(PostReply reply) {
return ListNotificationFilters.isReplyVisible(currentSone, reply);
}
});
}
/* remove replies to unknown posts. */
- newReplies = Filters.filteredSet(newReplies, new Filter<PostReply>() {
+ newReplies = Collections2.filter(newReplies, new Predicate<PostReply>() {
@Override
- public boolean filterObject(PostReply reply) {
+ public boolean apply(PostReply reply) {
return (reply.getPost() != null) && (reply.getPost().getSone() != null);
}
});