/*
- * Sone - KnownSonesPage.java - Copyright © 2010–2012 David Roden
+ * Sone - KnownSonesPage.java - Copyright © 2010–2013 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.web.page.FreenetRequest;
import net.pterodactylus.util.collection.Pagination;
-import net.pterodactylus.util.collection.ReverseComparator;
-import net.pterodactylus.util.number.Numbers;
import net.pterodactylus.util.template.Template;
import net.pterodactylus.util.template.TemplateContext;
+import com.google.common.base.Optional;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.collect.Collections2;
+import com.google.common.collect.Ordering;
+import com.google.common.primitives.Ints;
/**
* This page shows all known Sones.
List<Sone> sortedSones = new ArrayList<Sone>(knownSones);
if ("activity".equals(sortField)) {
if ("asc".equals(sortOrder)) {
- Collections.sort(sortedSones, new ReverseComparator<Sone>(Sone.LAST_ACTIVITY_COMPARATOR));
+ Collections.sort(sortedSones, Ordering.from(Sone.LAST_ACTIVITY_COMPARATOR).reverse());
} else {
Collections.sort(sortedSones, Sone.LAST_ACTIVITY_COMPARATOR);
}
} else if ("posts".equals(sortField)) {
if ("asc".equals(sortOrder)) {
- Collections.sort(sortedSones, new ReverseComparator<Sone>(Sone.POST_COUNT_COMPARATOR));
+ Collections.sort(sortedSones, Ordering.from(Sone.POST_COUNT_COMPARATOR).reverse());
} else {
Collections.sort(sortedSones, Sone.POST_COUNT_COMPARATOR);
}
} else if ("images".equals(sortField)) {
if ("asc".equals(sortOrder)) {
- Collections.sort(sortedSones, new ReverseComparator<Sone>(Sone.IMAGE_COUNT_COMPARATOR));
+ Collections.sort(sortedSones, Ordering.from(Sone.IMAGE_COUNT_COMPARATOR).reverse());
} else {
Collections.sort(sortedSones, Sone.IMAGE_COUNT_COMPARATOR);
}
} else {
if ("desc".equals(sortOrder)) {
- Collections.sort(sortedSones, new ReverseComparator<Sone>(Sone.NICE_NAME_COMPARATOR));
+ Collections.sort(sortedSones, Ordering.from(Sone.NICE_NAME_COMPARATOR).reverse());
} else {
Collections.sort(sortedSones, Sone.NICE_NAME_COMPARATOR);
}
}
- Pagination<Sone> sonePagination = new Pagination<Sone>(sortedSones, 25).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("page"), 0));
+ Pagination<Sone> sonePagination = new Pagination<Sone>(sortedSones, 25).setPage(Optional.fromNullable(Ints.tryParse(request.getHttpRequest().getParam("page"))).or(0));
templateContext.set("pagination", sonePagination);
templateContext.set("knownSones", sonePagination.getItems());
}