package envoy.client.data.commands; import java.util.*; import java.util.function.Consumer; /** * This class acts as a builder for {@link SystemCommand}s. * * @author Leon Hofmeister * @since Envoy Client v0.2-beta */ public final class SystemCommandBuilder { private int numberOfArguments; private Consumer> action; private List defaults; private String description; private int relevance; /** * @param numberOfArguments the numberOfArguments to set * @return this {@code SystemCommandBuilder} * @since Envoy Client v0.2-beta */ public SystemCommandBuilder setNumberOfArguments(int numberOfArguments) { this.numberOfArguments = numberOfArguments; return this; } /** * @param action the action to set * @return this {@code SystemCommandBuilder} * @since Envoy Client v0.2-beta */ public SystemCommandBuilder setAction(Consumer> action) { this.action = action; return this; } /** * @param description the description to set * @return this {@code SystemCommandBuilder} * @since Envoy Client v0.2-beta */ public SystemCommandBuilder setDescription(String description) { this.description = description; return this; } /** * @param relevance the relevance to set * @return this {@code SystemCommandBuilder} * @since Envoy Client v0.2-beta */ public SystemCommandBuilder setRelevance(int relevance) { this.relevance = relevance; return this; } /** * @param defaults the defaults to set * @return this {@code SystemCommandBuilder} * @since Envoy Client v0.2-beta */ public SystemCommandBuilder setDefaults(String... defaults) { this.defaults = List.of(defaults); return this; } /** * Resets all values stored. * * @return this {@code SystemCommandBuilder} * @since Envoy Client v0.2-beta */ public SystemCommandBuilder reset() { numberOfArguments = 0; action = null; defaults = new ArrayList<>(); description = ""; relevance = 0; return this; } /** * Builds a {@code SystemCommand} based upon the previously entered data. * * @return the built {@code SystemCommand} * @since Envoy Client v0.2-beta */ public SystemCommand build() { return build(true); } /** * Builds a {@code SystemCommand} based upon the previously entered data.
* {@code SystemCommand#numberOfArguments} will be set to 0, regardless of the * previous value.
* At the end, this {@code SystemCommandBuilder} will be reset. * * @return the built {@code SystemCommand} * @since Envoy Client v0.2-beta */ public SystemCommand buildNoArg() { numberOfArguments = 0; return build(true); } /** * Builds a {@code SystemCommand} based upon the previously entered data.
* {@code SystemCommand#numberOfArguments} will be set to use the rest of the * string as argument, regardless of the previous value.
* At the end, this {@code SystemCommandBuilder} will be reset. * * @return the built {@code SystemCommand} * @since Envoy Client v0.2-beta */ public SystemCommand buildRemainingArg() { numberOfArguments = -1; return build(true); } /** * Builds a {@code SystemCommand} based upon the previously entered data.
* At the end, this {@code SystemCommandBuilder} can be reset but must * not be. * * @param reset whether this {@code SystemCommandBuilder} should be reset * afterwards.
* This can be useful if another command wants to execute something * similar * @return the built {@code SystemCommand} * @since Envoy Client v0.2-beta */ public SystemCommand build(boolean reset) { final var sc = new SystemCommand(action, numberOfArguments, defaults, description); sc.setRelevance(relevance); if (reset) reset(); return sc; } }