Fix minor checkstyle issues
- Add JavaDoc where checkstyle expects it - Fix line too long issues - ...
This commit is contained in:
@@ -7,11 +7,20 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Utility functions for {@link CommandDescription} objects.
|
||||
*/
|
||||
public final class CommandUtils {
|
||||
|
||||
private CommandUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the minimum number of arguments required for running the command (= number of mandatory arguments).
|
||||
*
|
||||
* @param command the command to process
|
||||
* @return min number of arguments required by the command
|
||||
*/
|
||||
public static int getMinNumberOfArguments(CommandDescription command) {
|
||||
int mandatoryArguments = 0;
|
||||
for (CommandArgumentDescription argument : command.getArguments()) {
|
||||
@@ -22,20 +31,16 @@ public final class CommandUtils {
|
||||
return mandatoryArguments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum number of arguments the command accepts.
|
||||
*
|
||||
* @param command the command to process
|
||||
* @return max number of arguments that may be passed to the command
|
||||
*/
|
||||
public static int getMaxNumberOfArguments(CommandDescription command) {
|
||||
return command.getArguments().size();
|
||||
}
|
||||
|
||||
public static String constructCommandPath(CommandDescription command) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String prefix = "/";
|
||||
for (CommandDescription ancestor : constructParentList(command)) {
|
||||
sb.append(prefix).append(ancestor.getLabels().get(0));
|
||||
prefix = " ";
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a hierarchical list of commands for the given command. The commands are in order:
|
||||
* the parents of the given command precede the provided command. For example, given the command
|
||||
@@ -54,6 +59,29 @@ public final class CommandUtils {
|
||||
return Lists.reverse(commands);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a textual representation of the command, e.g. {@code /authme register}.
|
||||
*
|
||||
* @param command the command to create the path for
|
||||
* @return the command string
|
||||
*/
|
||||
public static String constructCommandPath(CommandDescription command) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String prefix = "/";
|
||||
for (CommandDescription ancestor : constructParentList(command)) {
|
||||
sb.append(prefix).append(ancestor.getLabels().get(0));
|
||||
prefix = " ";
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a textual representation of the command, including its arguments.
|
||||
* For example: {@code /authme purge <days> [includeZero]}.
|
||||
*
|
||||
* @param command the command to create a usage string for
|
||||
* @return the command's path and arguments
|
||||
*/
|
||||
public static String buildSyntax(CommandDescription command) {
|
||||
String arguments = command.getArguments().stream()
|
||||
.map(arg -> formatArgument(arg))
|
||||
@@ -73,12 +101,12 @@ public final class CommandUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a command argument with the proper type of brackets.
|
||||
* Formats a command argument with the proper type of brackets.
|
||||
*
|
||||
* @param argument the argument to format
|
||||
* @return the formatted argument
|
||||
*/
|
||||
public static String formatArgument(CommandArgumentDescription argument) {
|
||||
private static String formatArgument(CommandArgumentDescription argument) {
|
||||
if (argument.isOptional()) {
|
||||
return "[" + argument.getName() + "]";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user