Apply suggestions from code review (1)

Co-authored-by: CyB3RC0nN0R <kske@outlook.de>
This commit is contained in:
delvh 2020-07-23 18:51:20 +02:00 committed by GitHub
parent d3c2eb4ff7
commit e49d390089
3 changed files with 11 additions and 18 deletions

View File

@ -18,9 +18,6 @@ public interface OnCall {
/** /**
* Performs class specific actions when a {@link SystemCommand} has been called. * Performs class specific actions when a {@link SystemCommand} has been called.
* *
* The action that should be performed when this {@link SystemCommand} has been
* called.
*
* @since Envoy Client v0.2-beta * @since Envoy Client v0.2-beta
*/ */
void onCall(); void onCall();

View File

@ -24,13 +24,12 @@ import java.util.function.Supplier;
public class SystemCommand implements OnCall { public class SystemCommand implements OnCall {
/** /**
* This variable stores the amount of arguments that need to be parsed for the * The argument count of the command.
* underlying function.
*/ */
protected final int numberOfArguments; protected final int numberOfArguments;
/** /**
* This Function takes a {@code String[]} as argument because automatically * This function takes a {@code String[]} as argument because automatically
* {@code SystemCommand#numberOfArguments} words following the necessary command * {@code SystemCommand#numberOfArguments} words following the necessary command
* will be put into this array. * will be put into this array.
* *
@ -40,14 +39,13 @@ public class SystemCommand implements OnCall {
protected final String description; protected final String description;
protected int relevance = 0; protected int relevance;
/** /**
* Constructs a new {@code SystemCommand}. * Constructs a new {@code SystemCommand}.
* *
* @param action the action that should be performed * @param action the action performed by the command
* @param numberOfArguments the amount of arguments that need to be parsed for * @param numberOfArguments the argument count accepted by the action
* the underlying function
* @param description the description of this {@code SystemCommand} * @param description the description of this {@code SystemCommand}
* @since Envoy Client v0.2-beta * @since Envoy Client v0.2-beta
*/ */
@ -64,8 +62,7 @@ public class SystemCommand implements OnCall {
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 argument count of the command
* the underlying function
* @since Envoy Client v0.2-beta * @since Envoy Client v0.2-beta
*/ */
public int getNumberOfArguments() { return numberOfArguments; } public int getNumberOfArguments() { return numberOfArguments; }

View File

@ -19,7 +19,7 @@ import envoy.util.EnvoyLog;
* @author Leon Hofmeister * @author Leon Hofmeister
* @since Envoy Client v0.2-beta * @since Envoy Client v0.2-beta
*/ */
public class SystemCommandsMap { public final class SystemCommandsMap {
private final HashMap<String, SystemCommand> systemCommands = new HashMap<>(); private final HashMap<String, SystemCommand> systemCommands = new HashMap<>();
@ -27,11 +27,10 @@ public class SystemCommandsMap {
private static final Logger logger = EnvoyLog.getLogger(SystemCommandsMap.class); private static final Logger logger = EnvoyLog.getLogger(SystemCommandsMap.class);
private boolean commandExecuted = false; private boolean commandExecuted;
/** /**
* Adds a command with according action and the number of arguments that should * Adds a new command to the map if the command name is valid.
* be parsed if the command does not violate API constrictions to the map.
* *
* @param command the string that must be inputted to execute the * @param command the string that must be inputted to execute the
* given action * given action
@ -124,9 +123,9 @@ public class SystemCommandsMap {
* @return whether this key can be used in the map * @return whether this key can be used in the map
* @since Envoy Client v0.2-beta * @since Envoy Client v0.2-beta
*/ */
public final boolean isValidKey(String command) { public boolean isValidKey(String command) {
final boolean valid = commandBounds.matcher(command).matches(); final boolean valid = commandBounds.matcher(command).matches();
if (!valid) EnvoyLog.getLogger(SystemCommandsMap.class) if (!valid) logger
.log(Level.WARNING, .log(Level.WARNING,
"The command \"" + command "The command \"" + command
+ "\" is not valid. As it will cause problems in execution, it will not be entered into the map. Only the characters " + "\" is not valid. As it will cause problems in execution, it will not be entered into the map. Only the characters "