2 * XdccDownloader - ResearchCommand.java - Copyright © 2013 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.xdcc.ui.stdin;
20 import static java.util.Arrays.asList;
22 import java.io.IOException;
23 import java.io.Writer;
24 import java.util.Collection;
25 import java.util.Collections;
26 import java.util.List;
28 import net.pterodactylus.xdcc.core.Core;
29 import net.pterodactylus.xdcc.data.Download;
31 import com.google.common.primitives.Ints;
34 * Command that runs a search for the exact filename of a failed download.
36 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
38 public class ResearchCommand extends SearchCommand {
40 public ResearchCommand(Core core) {
45 public String getName() {
50 public Collection<String> getAliases() {
55 public State execute(State state, List<String> parameters, Writer outputWriter) throws IOException {
56 Integer index = Ints.tryParse(parameters.get(0));
57 List<Download> lastFailedDownloads = state.getLastFailedDownloads();
58 if ((index != null) && (index < lastFailedDownloads.size())) {
59 Download failedDownload = lastFailedDownloads.get(index);
60 return super.execute(state, asList(failedDownload.pack().name()), outputWriter);
62 return super.execute(state, Collections.<String>emptyList(), outputWriter);