2 * XdccDownloader - Command.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 java.io.IOException;
21 import java.io.Writer;
22 import java.util.Collection;
23 import java.util.List;
25 import com.google.common.base.Function;
28 * A command is executed by the {@link CommandReader}. It receives the current
29 * state of the command reader and can return a changed state, depending on the
32 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34 public interface Command {
36 /** Converts a command into its name. */
37 public static final Function<Command, String> TO_NAME = new Function<Command, String>() {
39 public String apply(Command command) {
40 return command.getName();
44 /** Converts a command into its aliases. */
45 public static final Function<Command, Collection<String>> TO_ALIASES = new Function<Command, Collection<String>>() {
47 public Collection<String> apply(Command command) {
48 return command.getAliases();
53 * Returns the name of this command.
55 * @return The name of this command
57 public String getName();
60 * Returns possible aliases for this command.
62 * @return Possible aliases for this command
64 public Collection<String> getAliases();
67 * Executes this command.
70 * The current state of the command reader
72 * The parameters given on the command line
74 * The output writer to write the output of the command to
75 * @return The new state of the command reader (which may be the given state if
76 * the command does not need to modify the state)
78 * if an I/O error occurs
80 public State execute(State state, List<String> parameters, Writer outputWriter) throws IOException;