package net.pterodactylus.sone.web;
+import static com.google.common.collect.FluentIterable.from;
+
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.Collections2;
-import com.google.common.collect.FluentIterable;
import com.google.common.collect.Ordering;
/**
// SONETEMPLATEPAGE METHODS
//
- /**
- * {@inheritDoc}
- */
@Override
@SuppressWarnings("synthetic-access")
protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
redirectIfNotNull(getImageId(phrase), "imageBrowser.html?image=");
}
- Set<Sone> sones = webInterface.getCore().getSones();
+ Collection<Sone> sones = webInterface.getCore().getSones();
Collection<Hit<Sone>> soneHits = getHits(sones, phrases, SoneStringGenerator.COMPLETE_GENERATOR);
Collection<Hit<Post>> postHits = hitCache.getUnchecked(phrases);
List<Hit<Post>> sortedPostHits = Ordering.from(Hit.DESCENDING_COMPARATOR).sortedCopy(postHits);
/* extract Sones and posts. */
- List<Sone> resultSones = FluentIterable.from(sortedSoneHits).transform(new HitMapper<Sone>()).toList();
- List<Post> resultPosts = FluentIterable.from(sortedPostHits).transform(new HitMapper<Post>()).toList();
+ List<Sone> resultSones = from(sortedSoneHits).transform(new HitMapper<Sone>()).toList();
+ List<Post> resultPosts = from(sortedPostHits).transform(new HitMapper<Post>()).toList();
/* pagination. */
Pagination<Sone> sonePagination = new Pagination<Sone>(resultSones, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("sonePage"), 0));
*/
private String getSoneId(String phrase) {
String soneId = phrase.startsWith("sone://") ? phrase.substring(7) : phrase;
- return (webInterface.getCore().getSone(soneId) != null) ? soneId : null;
+ return (webInterface.getCore().getSone(soneId).isPresent()) ? soneId : null;
}
/**
*/
private String getPostId(String phrase) {
String postId = phrase.startsWith("post://") ? phrase.substring(7) : phrase;
- return (webInterface.getCore().getPost(postId).isPresent()) ? postId : null;
+ return (webInterface.getCore().getDatabase().getPost(postId).isPresent()) ? postId : null;
}
/**
*/
private String getReplyPostId(String phrase) {
String replyId = phrase.startsWith("reply://") ? phrase.substring(8) : phrase;
- Optional<PostReply> postReply = webInterface.getCore().getPostReply(replyId);
+ Optional<PostReply> postReply = webInterface.getCore().getDatabase().getPostReply(replyId);
if (!postReply.isPresent()) {
return null;
}
*/
private String getAlbumId(String phrase) {
String albumId = phrase.startsWith("album://") ? phrase.substring(8) : phrase;
- return (webInterface.getCore().getAlbum(albumId, false) != null) ? albumId : null;
+ return webInterface.getCore().getAlbum(albumId).isPresent() ? albumId : null;
}
/**
*/
private String getImageId(String phrase) {
String imageId = phrase.startsWith("image://") ? phrase.substring(8) : phrase;
- return (webInterface.getCore().getImage(imageId, false) != null) ? imageId : null;
+ return webInterface.getCore().getImage(imageId).isPresent() ? imageId : null;
}
/**
this.complete = complete;
}
- /**
- * {@inheritDoc}
- */
@Override
public String generateString(Sone sone) {
StringBuilder soneString = new StringBuilder();
*/
private class PostStringGenerator implements StringGenerator<Post> {
- /**
- * {@inheritDoc}
- */
@Override
public String generateString(Post post) {
StringBuilder postString = new StringBuilder();
if (post.getRecipient().isPresent()) {
postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(post.getRecipient().get()));
}
- for (PostReply reply : Collections2.filter(webInterface.getCore().getReplies(post), Reply.FUTURE_REPLY_FILTER)) {
+ for (PostReply reply : from(post.getReplies()).filter(Reply.FUTURE_REPLY_FILTER)) {
postString.append(' ').append(SoneStringGenerator.NAME_GENERATOR.generateString(reply.getSone()));
postString.append(' ').append(reply.getText());
}
// OBJECT METHODS
//
- /**
- * {@inheritDoc}
- */
@Override
public int hashCode() {
return phrase.hashCode() ^ ((optionality == Optionality.FORBIDDEN) ? (0xaaaaaaaa) : ((optionality == Optionality.REQUIRED) ? 0x55555555 : 0));
}
- /**
- * {@inheritDoc}
- */
@Override
public boolean equals(Object object) {
if (!(object instanceof Phrase)) {
@Override
public boolean apply(Hit<?> hit) {
- return hit.getScore() > 0;
+ return (hit == null) ? false : hit.getScore() > 0;
}
};
*/
private static class HitMapper<T> implements Function<Hit<T>, T> {
- /**
- * {@inheritDoc}
- */
@Override
public T apply(Hit<T> input) {
return input.getObject();