create comparator only once

This commit is contained in:
Athou
2026-04-27 17:57:30 +02:00
parent fd13c80e5a
commit f826f1d543
3 changed files with 17 additions and 5 deletions

View File

@@ -50,6 +50,8 @@ public class FeedParser {
private static final Instant START = Instant.ofEpochMilli(86400000);
private static final Instant END = Instant.ofEpochMilli(1000L * Integer.MAX_VALUE - 86400000);
private static final Comparator<Entry> ENTRY_COMPARATOR = Comparator.comparing(Entry::published).reversed();
private final EncodingDetector encodingDetector;
private final FeedCleaner feedCleaner;
@@ -138,7 +140,7 @@ public class FeedParser {
entries.add(new Entry(guid, url, publishedDate, content));
}
entries.sort(Comparator.comparing(Entry::published).reversed());
entries.sort(ENTRY_COMPARATOR);
return entries;
}

View File

@@ -23,6 +23,11 @@ import lombok.RequiredArgsConstructor;
@Singleton
public class OPMLExporter {
private static final Comparator<FeedCategory> CATEGORY_COMPARATOR = Comparator
.comparingInt(e -> ObjectUtils.firstNonNull(e.getPosition(), 0));
private static final Comparator<FeedSubscription> SUBSCRIPTION_COMPARATOR = Comparator
.comparingInt(e -> ObjectUtils.firstNonNull(e.getPosition(), 0));
private final FeedCategoryDAO feedCategoryDAO;
private final FeedSubscriptionDAO feedSubscriptionDAO;
@@ -33,10 +38,10 @@ public class OPMLExporter {
opml.setCreated(new Date());
List<FeedCategory> categories = feedCategoryDAO.findAll(user);
categories.sort(Comparator.comparingInt(e -> ObjectUtils.firstNonNull(e.getPosition(), 0)));
categories.sort(CATEGORY_COMPARATOR);
List<FeedSubscription> subscriptions = feedSubscriptionDAO.findAll(user);
subscriptions.sort(Comparator.comparingInt(e -> ObjectUtils.firstNonNull(e.getPosition(), 0)));
subscriptions.sort(SUBSCRIPTION_COMPARATOR);
// export root categories
for (FeedCategory cat : categories.stream().filter(c -> c.getParent() == null).toList()) {

View File

@@ -84,6 +84,11 @@ public class CategoryREST {
public static final String ALL = "all";
public static final String STARRED = "starred";
private static final Comparator<Category> CATEGORY_COMPARATOR = Comparator.comparing(Category::getPosition)
.thenComparing(Category::getName);
private static final Comparator<Subscription> SUBSCRIPTION_COMPARATOR = Comparator.comparing(Subscription::getPosition)
.thenComparing(Subscription::getName);
private final AuthenticationContext authenticationContext;
private final FeedCategoryDAO feedCategoryDAO;
private final FeedEntryStatusDAO feedEntryStatusDAO;
@@ -432,7 +437,7 @@ public class CategoryREST {
category.getChildren().add(child);
}
}
category.getChildren().sort(Comparator.comparing(Category::getPosition).thenComparing(Category::getName));
category.getChildren().sort(CATEGORY_COMPARATOR);
for (FeedSubscription subscription : subscriptions) {
if (id == null && subscription.getCategory() == null
@@ -442,7 +447,7 @@ public class CategoryREST {
category.getFeeds().add(sub);
}
}
category.getFeeds().sort(Comparator.comparing(Subscription::getPosition).thenComparing(Subscription::getName));
category.getFeeds().sort(SUBSCRIPTION_COMPARATOR);
return category;
}