X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fxdcc%2Fdata%2FDownload.java;h=9664f7c477834b9efdcf85cd55b98b2db5747a71;hb=5d31ca8229a8ad96822788015313bf5adada892e;hp=560e7f9ae572f9255eafaa198073001fb5a047c8;hpb=e23a2a9e59408fce266a6cac4b11cb5b311881e1;p=xudocci.git diff --git a/src/main/java/net/pterodactylus/xdcc/data/Download.java b/src/main/java/net/pterodactylus/xdcc/data/Download.java index 560e7f9..9664f7c 100644 --- a/src/main/java/net/pterodactylus/xdcc/data/Download.java +++ b/src/main/java/net/pterodactylus/xdcc/data/Download.java @@ -27,6 +27,8 @@ import java.util.concurrent.atomic.AtomicReference; import net.pterodactylus.irc.DccReceiver; +import com.google.common.base.Function; +import com.google.common.base.Optional; import com.google.common.base.Predicate; /** @@ -63,6 +65,22 @@ public class Download { } }; + /** + * Converts a download into the number of seconds left in the transfer at the + * current rate. + */ + public static final Function> SECONDS_LEFT = new Function>() { + @Override + public Optional 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); + } + }; + /** The bot that is being downloaded from. */ private final Bot bot;