+ /** Predicate that identifies downloads that have started. */
+ public static final Predicate<Download> FILTER_RUNNING = new Predicate<Download>() {
+
+ @Override
+ public boolean apply(Download download) {
+ return download.dccReceiver() != null;
+ }
+ };
+
+ /** {@link Comparator} that sorts downloads by their name. */
+ public static final Comparator<Download> BY_NAME = new Comparator<Download>() {
+
+ @Override
+ public int compare(Download leftDownload, Download rightDownload) {
+ return leftDownload.pack().name().compareToIgnoreCase(rightDownload.pack().name());
+ }
+ };
+
+ /** {@link Comparator} that sorts running downloads first. */
+ public static final Comparator<Download> BY_RUNNING = new Comparator<Download>() {
+
+ @Override
+ public int compare(Download leftDownload, Download rightDownload) {
+ return (leftDownload.dccReceiver() != null) ? -1 : (rightDownload.dccReceiver() != null) ? 1 : 0;
+ }
+ };
+
+ /**
+ * Converts a download into the number of seconds left in the transfer at the
+ * current rate.
+ */
+ public static final Function<Download, Optional<Long>> SECONDS_LEFT = new Function<Download, Optional<Long>>() {
+ @Override
+ public Optional<Long> apply(Download download) {
+ DccReceiver dccReceiver = download.dccReceiver();
+ if ((dccReceiver == null) || (dccReceiver.size() == -1) || (dccReceiver.currentRate() == 0)) {
+ return Optional.absent();
+ }
+ long secondsLeft = (dccReceiver.size() - dccReceiver.progress()) / dccReceiver.currentRate();
+ return Optional.of(secondsLeft);
+ }
+ };
+