rewrite using lambdas

This commit is contained in:
Athou
2014-12-12 10:06:23 +01:00
parent 2e475c35cc
commit 504e4eab3e
15 changed files with 44 additions and 150 deletions

View File

@@ -13,7 +13,6 @@ import com.commafeed.backend.dao.FeedSubscriptionDAO;
import com.commafeed.backend.model.FeedCategory;
import com.commafeed.backend.model.FeedSubscription;
import com.commafeed.backend.model.User;
import com.google.common.base.Function;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import com.rometools.opml.feed.opml.Attribute;
@@ -24,13 +23,7 @@ import com.rometools.opml.feed.opml.Outline;
@Singleton
public class OPMLExporter {
private static Long ROOT_CATEGORY_ID = new Long(-1);
private static final Function<FeedSubscription, Long> SUBSCRIPTION_TO_CATEGORYID = new Function<FeedSubscription, Long>() {
@Override
public Long apply(FeedSubscription sub) {
return sub.getCategory() == null ? ROOT_CATEGORY_ID : sub.getCategory().getId();
}
};
private static Long ROOT_CATEGORY_ID = Long.valueOf(Long.MIN_VALUE);
private final FeedCategoryDAO feedCategoryDAO;
private final FeedSubscriptionDAO feedSubscriptionDAO;
@@ -42,7 +35,8 @@ public class OPMLExporter {
opml.setCreated(new Date());
List<FeedCategory> categories = feedCategoryDAO.findAll(user);
Multimap<Long, FeedSubscription> subscriptions = Multimaps.index(feedSubscriptionDAO.findAll(user), SUBSCRIPTION_TO_CATEGORYID);
Multimap<Long, FeedSubscription> subscriptions = Multimaps.index(feedSubscriptionDAO.findAll(user),
sub -> sub.getCategory() == null ? ROOT_CATEGORY_ID : sub.getCategory().getId());
// export root categories
for (FeedCategory cat : categories) {