76 lines
2.4 KiB
Java
76 lines
2.4 KiB
Java
package envoy.client.data.commands;
|
|
|
|
import java.util.function.Function;
|
|
|
|
/**
|
|
* This class is the base class of all {@code SystemCommands} and contains an
|
|
* action and a number of arguments that should be used as input for this
|
|
* function.
|
|
* No {@code SystemCommand} can return anything.
|
|
* Every {@code SystemCommand} must have as argument type {@code String[]} so
|
|
* that the words following the indicator String can be used as input of the
|
|
* function. This approach has one limitation:<br>
|
|
* <b>Order matters!</b> Changing the order of arguments will likely result in
|
|
* unexpected behavior.
|
|
* <p>
|
|
* Project: <strong>envoy-client</strong><br>
|
|
* File: <strong>SystemCommand.java</strong><br>
|
|
* Created: <strong>16.07.2020</strong><br>
|
|
*
|
|
* @author Leon Hofmeister
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public final class SystemCommand {
|
|
|
|
/**
|
|
* This variable stores the amount of arguments that need to be parsed for the
|
|
* underlying function.
|
|
*/
|
|
protected final int numberOfArguments;
|
|
|
|
/**
|
|
* This Function takes a {@code String[]} as argument because automatically
|
|
* {@code SystemCommand#numberOfArguments} words following the necessary command
|
|
* will be put into this array.
|
|
*
|
|
* @see String#split(String)
|
|
*/
|
|
protected final Function<String[], Void> action;
|
|
|
|
protected final String description;
|
|
|
|
/**
|
|
* Constructs a new {@code NoArgSystemCommand} that takes no arguments.
|
|
*
|
|
* @param action the action that should be performed
|
|
* @param numberOfArguments the amount of arguments that need to be parsed for
|
|
* the underlying function
|
|
* @param description the description of this {@code SystemCommand}
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public SystemCommand(Function<String[], Void> action, int numberOfArguments, String description) {
|
|
this.numberOfArguments = numberOfArguments;
|
|
this.action = action;
|
|
this.description = description;
|
|
}
|
|
|
|
/**
|
|
* @return the action that should be performed
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public Function<String[], Void> getAction() { return action; }
|
|
|
|
/**
|
|
* @return the amount of arguments that need to be parsed for
|
|
* the underlying function
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public int getNumberOfArguments() { return numberOfArguments; }
|
|
|
|
/**
|
|
* @return the description
|
|
* @since Envoy Client v0.1-beta
|
|
*/
|
|
public String getDescription() { return description; }
|
|
}
|