Adjusted formatter to new Envoy version
This commit is contained in:
parent
34036d275a
commit
74aa00235e
File diff suppressed because one or more lines are too long
@ -18,7 +18,7 @@ import java.util.function.Function;
|
|||||||
* Created: <strong>16.07.2020</strong><br>
|
* Created: <strong>16.07.2020</strong><br>
|
||||||
*
|
*
|
||||||
* @author Leon Hofmeister
|
* @author Leon Hofmeister
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public final class SystemCommand {
|
public final class SystemCommand {
|
||||||
|
|
||||||
@ -46,7 +46,7 @@ public final class SystemCommand {
|
|||||||
* @param numberOfArguments the amount of arguments that need to be parsed for
|
* @param numberOfArguments the amount of arguments that need to be parsed for
|
||||||
* the underlying function
|
* the underlying function
|
||||||
* @param description the description of this {@code SystemCommand}
|
* @param description the description of this {@code SystemCommand}
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public SystemCommand(Function<String[], Void> action, int numberOfArguments, String description) {
|
public SystemCommand(Function<String[], Void> action, int numberOfArguments, String description) {
|
||||||
this.numberOfArguments = numberOfArguments;
|
this.numberOfArguments = numberOfArguments;
|
||||||
@ -56,20 +56,20 @@ public final class SystemCommand {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the action that should be performed
|
* @return the action that should be performed
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public Function<String[], Void> getAction() { return action; }
|
public Function<String[], Void> getAction() { return action; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the amount of arguments that need to be parsed for
|
* @return the amount of arguments that need to be parsed for
|
||||||
* the underlying function
|
* the underlying function
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public int getNumberOfArguments() { return numberOfArguments; }
|
public int getNumberOfArguments() { return numberOfArguments; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the description
|
* @return the description
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public String getDescription() { return description; }
|
public String getDescription() { return description; }
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package envoy.client.data.commands;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -16,9 +17,7 @@ import envoy.util.EnvoyLog;
|
|||||||
* Created: <strong>17.07.2020</strong><br>
|
* Created: <strong>17.07.2020</strong><br>
|
||||||
*
|
*
|
||||||
* @author Leon Hofmeister
|
* @author Leon Hofmeister
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
* @apiNote Please refrain from using the "/"-char in keys of this map.
|
|
||||||
* Unexpected behavior will occur.
|
|
||||||
*/
|
*/
|
||||||
public class SystemCommandsMap {
|
public class SystemCommandsMap {
|
||||||
|
|
||||||
@ -26,6 +25,8 @@ public class SystemCommandsMap {
|
|||||||
|
|
||||||
private final Pattern commandBounds = Pattern.compile("^[a-zA-Z0-9_:!\\(\\)\\?\\.\\,\\;\\-]+$");
|
private final Pattern commandBounds = Pattern.compile("^[a-zA-Z0-9_:!\\(\\)\\?\\.\\,\\;\\-]+$");
|
||||||
|
|
||||||
|
private static final Logger logger = EnvoyLog.getLogger(SystemCommandsMap.class);
|
||||||
|
|
||||||
private boolean commandExecuted = false;
|
private boolean commandExecuted = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -38,7 +39,7 @@ public class SystemCommandsMap {
|
|||||||
* @param numberOfArguments the amount of arguments that need to be parsed for
|
* @param numberOfArguments the amount of arguments that need to be parsed for
|
||||||
* the underlying function
|
* the underlying function
|
||||||
* @see SystemCommandsMap#isValidKey(String)
|
* @see SystemCommandsMap#isValidKey(String)
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public void addCommand(String command, Function<String[], Void> action, int numberOfArguments) {
|
public void addCommand(String command, Function<String[], Void> action, int numberOfArguments) {
|
||||||
if (isValidKey(command)) systemCommands.put(command, new SystemCommand(action, numberOfArguments, ""));
|
if (isValidKey(command)) systemCommands.put(command, new SystemCommand(action, numberOfArguments, ""));
|
||||||
@ -56,7 +57,7 @@ public class SystemCommandsMap {
|
|||||||
* the underlying function
|
* the underlying function
|
||||||
* @param description the description of this {@link SystemCommand}
|
* @param description the description of this {@link SystemCommand}
|
||||||
* @see SystemCommandsMap#isValidKey(String)
|
* @see SystemCommandsMap#isValidKey(String)
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public void addCommand(String command, Function<String[], Void> action, int numberOfArguments, String description) {
|
public void addCommand(String command, Function<String[], Void> action, int numberOfArguments, String description) {
|
||||||
if (isValidKey(command)) systemCommands.put(command, new SystemCommand(action, numberOfArguments, description));
|
if (isValidKey(command)) systemCommands.put(command, new SystemCommand(action, numberOfArguments, description));
|
||||||
@ -70,7 +71,7 @@ public class SystemCommandsMap {
|
|||||||
* @param action the action that should be performed. To see why this Function
|
* @param action the action that should be performed. To see why this Function
|
||||||
* takes a {@code String[]}, see {@link SystemCommand}
|
* takes a {@code String[]}, see {@link SystemCommand}
|
||||||
* @see SystemCommandsMap#isValidKey(String)
|
* @see SystemCommandsMap#isValidKey(String)
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public void addNoArgCommand(String command, Function<String[], Void> action) { addCommand(command, action, 0); }
|
public void addNoArgCommand(String command, Function<String[], Void> action) { addCommand(command, action, 0); }
|
||||||
|
|
||||||
@ -86,7 +87,7 @@ public class SystemCommandsMap {
|
|||||||
* {@link SystemCommand}
|
* {@link SystemCommand}
|
||||||
* @param description the description of this {@link SystemCommand}
|
* @param description the description of this {@link SystemCommand}
|
||||||
* @see SystemCommandsMap#isValidKey(String)
|
* @see SystemCommandsMap#isValidKey(String)
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public void addNoArgCommand(String command, Function<String[], Void> action, String description) { addCommand(command, action, 0); }
|
public void addNoArgCommand(String command, Function<String[], Void> action, String description) { addCommand(command, action, 0); }
|
||||||
|
|
||||||
@ -105,7 +106,7 @@ public class SystemCommandsMap {
|
|||||||
* @param numberOfArguments the amount of arguments that need to be parsed for
|
* @param numberOfArguments the amount of arguments that need to be parsed for
|
||||||
* the underlying function
|
* the underlying function
|
||||||
* @see SystemCommandsMap#isValidKey(String)
|
* @see SystemCommandsMap#isValidKey(String)
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public void add(String command, Function<String[], Void> action, int numberOfArguments) { addCommand(command, action, numberOfArguments); }
|
public void add(String command, Function<String[], Void> action, int numberOfArguments) { addCommand(command, action, numberOfArguments); }
|
||||||
|
|
||||||
@ -121,7 +122,7 @@ public class SystemCommandsMap {
|
|||||||
*
|
*
|
||||||
* @param command the key to examine
|
* @param command the key to examine
|
||||||
* @return whether this key can be used in the map
|
* @return whether this key can be used in the map
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public final boolean isValidKey(String command) {
|
public final boolean isValidKey(String command) {
|
||||||
final boolean valid = commandBounds.matcher(command).matches();
|
final boolean valid = commandBounds.matcher(command).matches();
|
||||||
@ -150,7 +151,7 @@ public class SystemCommandsMap {
|
|||||||
*
|
*
|
||||||
* @param input the input string given by the user, <b>excluding the "/"</b>
|
* @param input the input string given by the user, <b>excluding the "/"</b>
|
||||||
* @return the wrapped system command, if present
|
* @return the wrapped system command, if present
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public Optional<SystemCommand> checkPresent(String input) {
|
public Optional<SystemCommand> checkPresent(String input) {
|
||||||
final var firstWord = input.substring(0, input.indexOf(" "));
|
final var firstWord = input.substring(0, input.indexOf(" "));
|
||||||
@ -165,7 +166,7 @@ public class SystemCommandsMap {
|
|||||||
* continued.
|
* continued.
|
||||||
*
|
*
|
||||||
* @param raw the raw input string
|
* @param raw the raw input string
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public void checkForCommands(String raw) { checkForCommands(raw, 0); }
|
public void checkForCommands(String raw) { checkForCommands(raw, 0); }
|
||||||
|
|
||||||
@ -179,7 +180,7 @@ public class SystemCommandsMap {
|
|||||||
*
|
*
|
||||||
* @param raw the raw input string
|
* @param raw the raw input string
|
||||||
* @param fromIndex the index to start checking on
|
* @param fromIndex the index to start checking on
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public void checkForCommands(String raw, int fromIndex) {
|
public void checkForCommands(String raw, int fromIndex) {
|
||||||
// The minimum length of a command is "/" + a letter, hence raw.length()-2 is
|
// The minimum length of a command is "/" + a letter, hence raw.length()-2 is
|
||||||
@ -215,7 +216,7 @@ public class SystemCommandsMap {
|
|||||||
* result: {@code button.getText()=="xyz"}
|
* result: {@code button.getText()=="xyz"}
|
||||||
*
|
*
|
||||||
* @param input the input string given by the user, <b>excluding the "/"</b>
|
* @param input the input string given by the user, <b>excluding the "/"</b>
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public void executeIfPresent(String input) {
|
public void executeIfPresent(String input) {
|
||||||
checkPresent(input).ifPresent(systemCommand -> {
|
checkPresent(input).ifPresent(systemCommand -> {
|
||||||
@ -231,7 +232,7 @@ public class SystemCommandsMap {
|
|||||||
systemCommand.getAction().apply(arguments);
|
systemCommand.getAction().apply(arguments);
|
||||||
commandExecuted = true;
|
commandExecuted = true;
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
EnvoyLog.getLogger(SystemCommandsMap.class).log(Level.WARNING, "The system command " +
|
logger.log(Level.WARNING, "The system command " +
|
||||||
// detected command
|
// detected command
|
||||||
input.substring(0, input.indexOf(" ")) + " threw an exception: ", e);
|
input.substring(0, input.indexOf(" ")) + " threw an exception: ", e);
|
||||||
}
|
}
|
||||||
@ -248,7 +249,7 @@ public class SystemCommandsMap {
|
|||||||
* @param input the input
|
* @param input the input
|
||||||
* @param action the action that should be taken for the recommendations, if any
|
* @param action the action that should be taken for the recommendations, if any
|
||||||
* are present
|
* are present
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public void requestRecommendations(String input, Function<Set<String>, Void> action) { requestRecommendations(input, 0, action); }
|
public void requestRecommendations(String input, Function<Set<String>, Void> action) { requestRecommendations(input, 0, action); }
|
||||||
|
|
||||||
@ -263,7 +264,7 @@ public class SystemCommandsMap {
|
|||||||
* @param fromIndex the index to start checking on
|
* @param fromIndex the index to start checking on
|
||||||
* @param action the action that should be taken for the recommendations, if
|
* @param action the action that should be taken for the recommendations, if
|
||||||
* any are present
|
* any are present
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
private void requestRecommendations(String input, int fromIndex, Function<Set<String>, Void> action) {
|
private void requestRecommendations(String input, int fromIndex, Function<Set<String>, Void> action) {
|
||||||
final var partialCommand = input.substring(fromIndex + (input.charAt(fromIndex) == '/' ? 1 : 0), input.indexOf(" "));
|
final var partialCommand = input.substring(fromIndex + (input.charAt(fromIndex) == '/' ? 1 : 0), input.indexOf(" "));
|
||||||
@ -281,6 +282,7 @@ public class SystemCommandsMap {
|
|||||||
*
|
*
|
||||||
* @param partialCommand the partially entered command
|
* @param partialCommand the partially entered command
|
||||||
* @return a set of all commands that match this input
|
* @return a set of all commands that match this input
|
||||||
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
private Set<String> recommendCommands(String partialCommand) {
|
private Set<String> recommendCommands(String partialCommand) {
|
||||||
// current implementation only looks if input is contained within a command,
|
// current implementation only looks if input is contained within a command,
|
||||||
@ -290,7 +292,7 @@ public class SystemCommandsMap {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @return all {@link SystemCommand}s used with the underlying command as key
|
* @return all {@link SystemCommand}s used with the underlying command as key
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
public HashMap<String, SystemCommand> getSystemCommands() { return systemCommands; }
|
public HashMap<String, SystemCommand> getSystemCommands() { return systemCommands; }
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,6 @@
|
|||||||
* Created: <strong>16.07.2020</strong><br>
|
* Created: <strong>16.07.2020</strong><br>
|
||||||
*
|
*
|
||||||
* @author Leon Hofmeister
|
* @author Leon Hofmeister
|
||||||
* @since Envoy Client v0.1-beta
|
* @since Envoy Client v0.2-beta
|
||||||
*/
|
*/
|
||||||
package envoy.client.data.commands;
|
package envoy.client.data.commands;
|
||||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user