import org.apache.commons.lang3.StringEscapeUtils;
import com.google.common.collect.Lists;
+import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
/**
htmlBuilder.append("</tr>\n");
htmlBuilder.append("</thead>\n");
htmlBuilder.append("<tbody>\n");
- for (TorrentFile torrentFile : allTorrentFiles) {
+ for (TorrentFile torrentFile : sortNewFirst().sortedCopy(allTorrentFiles)) {
if (newTorrentFiles.contains(torrentFile)) {
htmlBuilder.append("<tr style=\"color: #008000; font-weight: bold;\">");
} else {
return htmlBuilder.toString();
}
+ /**
+ * Returns an ordering that sorts torrent files by whether they are new
+ * (according to {@link #newTorrentFiles}) or not. New files will be sorted
+ * first.
+ *
+ * @return An ordering for “new files first”
+ */
+ private Ordering<TorrentFile> sortNewFirst() {
+ return new Ordering<TorrentFile>() {
+
+ @Override
+ public int compare(TorrentFile leftTorrentFile, TorrentFile rightTorrentFile) {
+ if (newTorrentFiles.contains(leftTorrentFile) && !newTorrentFiles.contains(rightTorrentFile)) {
+ return -1;
+ }
+ if (!newTorrentFiles.contains(leftTorrentFile) && newTorrentFiles.contains(rightTorrentFile)) {
+ return 1;
+ }
+ return 0;
+ }
+ };
+ }
+
}