summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/cli
diff options
context:
space:
mode:
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/cli')
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/CLICommander.java60
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/CommandHandler.java2
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/CommandHelp.java8
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/CommandMode.java6
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/DelegatingCommand.java10
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java14
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java140
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java26
-rw-r--r--BJC-Utils2/src/main/java/bjc/utils/cli/NullHelp.java3
9 files changed, 137 insertions, 132 deletions
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/CLICommander.java b/BJC-Utils2/src/main/java/bjc/utils/cli/CLICommander.java
index 56a4be0..cccb255 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/CLICommander.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/CLICommander.java
@@ -16,9 +16,9 @@ public class CLICommander {
/*
* The streams used for input and normal/error output.
*/
- private InputStream input;
- private OutputStream output;
- private OutputStream error;
+ private final InputStream input;
+ private final OutputStream output;
+ private final OutputStream error;
/*
* The command mode to start execution in.
@@ -35,14 +35,16 @@ public class CLICommander {
* @param error
* The stream to send error output to.
*/
- public CLICommander(InputStream input, OutputStream output, OutputStream error) {
- if(input == null) throw new NullPointerException("Input stream must not be null");
- else if(output == null) throw new NullPointerException("Output stream must not be null");
- else if(error == null) throw new NullPointerException("Error stream must not be null");
-
- this.input = input;
+ public CLICommander(final InputStream input, final OutputStream output, final OutputStream error) {
+ if (input == null)
+ throw new NullPointerException("Input stream must not be null");
+ else if (output == null)
+ throw new NullPointerException("Output stream must not be null");
+ else if (error == null) throw new NullPointerException("Error stream must not be null");
+
+ this.input = input;
this.output = output;
- this.error = error;
+ this.error = error;
}
/**
@@ -50,10 +52,10 @@ public class CLICommander {
*/
public void runCommands() {
/*
- * Setup output streams.
+ * Setup output streams.
*/
- PrintStream normalOutput = new PrintStream(output);
- PrintStream errorOutput = new PrintStream(error);
+ final PrintStream normalOutput = new PrintStream(output);
+ final PrintStream errorOutput = new PrintStream(error);
/*
* Set up input streams.
@@ -62,7 +64,7 @@ public class CLICommander {
* stream multiple times.
*/
@SuppressWarnings("resource")
- Scanner inputSource = new Scanner(input);
+ final Scanner inputSource = new Scanner(input);
/*
* The mode currently being used to handle commands.
@@ -72,42 +74,42 @@ public class CLICommander {
CommandMode currentMode = initialMode;
/*
- * Process commands until we're told to stop.
+ * Process commands until we're told to stop.
*/
- while(currentMode != null) {
+ while (currentMode != null) {
/*
* Print out the command prompt, using a custom prompt
* if one is specified.
*/
- if(currentMode.isCustomPromptEnabled()) {
+ if (currentMode.isCustomPromptEnabled()) {
normalOutput.print(currentMode.getCustomPrompt());
} else {
normalOutput.print(currentMode.getName() + ">> ");
}
/*
- * Read in a command.
+ * Read in a command.
*/
- String currentLine = inputSource.nextLine();
+ final String currentLine = inputSource.nextLine();
/*
- * Handle commands we can handle.
+ * Handle commands we can handle.
*/
- if(currentMode.canHandle(currentLine)) {
- String[] commandTokens = currentLine.split(" ");
- String[] commandArgs = null;
+ if (currentMode.canHandle(currentLine)) {
+ final String[] commandTokens = currentLine.split(" ");
+ String[] commandArgs = null;
- int argCount = commandTokens.length;
+ final int argCount = commandTokens.length;
/*
- * Parse args if they are present.
+ * Parse args if they are present.
*/
- if(argCount > 1) {
+ if (argCount > 1) {
commandArgs = Arrays.copyOfRange(commandTokens, 1, argCount);
}
/*
- * Process command.
+ * Process command.
*/
currentMode = currentMode.process(commandTokens[0], commandArgs);
} else {
@@ -124,8 +126,8 @@ public class CLICommander {
* @param initialMode
* The initial command mode to use.
*/
- public void setInitialCommandMode(CommandMode initialMode) {
- if(initialMode == null) throw new NullPointerException("Initial mode must be non-zero");
+ public void setInitialCommandMode(final CommandMode initialMode) {
+ if (initialMode == null) throw new NullPointerException("Initial mode must be non-zero");
this.initialMode = initialMode;
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/CommandHandler.java b/BJC-Utils2/src/main/java/bjc/utils/cli/CommandHandler.java
index 0a3534f..2548248 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/CommandHandler.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/CommandHandler.java
@@ -18,7 +18,7 @@ public interface CommandHandler extends Function<String[], CommandMode> {
* @return The command mode to switch to after this command, or null to
* stop executing commands
*/
- default CommandMode handle(String[] args) {
+ default CommandMode handle(final String[] args) {
return this.apply(args);
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/CommandHelp.java b/BJC-Utils2/src/main/java/bjc/utils/cli/CommandHelp.java
index 68ed41a..86567a0 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/CommandHelp.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/CommandHelp.java
@@ -18,8 +18,12 @@ public interface CommandHelp {
* Get the summary line for a command.
*
* A summary line should consist of a string of the following format
- * <pre>"&lt;command-name>\t&lt;command-summary>"</pre> where anything in angle brackets
- * should be filled in.
+ *
+ * <pre>
+ * "&lt;command-name>\t&lt;command-summary>"
+ * </pre>
+ *
+ * where anything in angle brackets should be filled in.
*
* @return The summary line line for a command
*/
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/CommandMode.java b/BJC-Utils2/src/main/java/bjc/utils/cli/CommandMode.java
index d26b176..39c72fc 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/CommandMode.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/CommandMode.java
@@ -16,7 +16,7 @@ public interface CommandMode extends Comparable<CommandMode> {
* @return Whether or not this mode can handle the command. It is
* assumed not by default
*/
- default boolean canHandle(String command) {
+ default boolean canHandle(final String command) {
return false;
};
@@ -61,12 +61,12 @@ public interface CommandMode extends Comparable<CommandMode> {
* @return The command mode to use for the next command. Defaults to
* returning this, and doing nothing else
*/
- default CommandMode process(String command, String[] args) {
+ default CommandMode process(final String command, final String[] args) {
return this;
}
@Override
- default int compareTo(CommandMode o) {
+ default int compareTo(final CommandMode o) {
return getName().compareTo(o.getName());
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/DelegatingCommand.java b/BJC-Utils2/src/main/java/bjc/utils/cli/DelegatingCommand.java
index dbbb047..acaa3a6 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/DelegatingCommand.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/DelegatingCommand.java
@@ -10,7 +10,7 @@ class DelegatingCommand implements Command {
/*
* The command to delegate to.
*/
- private Command delegate;
+ private final Command delegate;
/**
* Create a new command that delegates to another command.
@@ -18,7 +18,7 @@ class DelegatingCommand implements Command {
* @param delegate
* The command to delegate to.
*/
- public DelegatingCommand(Command delegate) {
+ public DelegatingCommand(final Command delegate) {
this.delegate = delegate;
}
@@ -44,15 +44,15 @@ class DelegatingCommand implements Command {
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
+ final StringBuilder builder = new StringBuilder();
builder.append("DelegatingCommand [");
- if(delegate != null) {
+ if (delegate != null) {
builder.append("delegate=");
builder.append(delegate);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java
index c49b4b9..4ae4dea 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java
@@ -10,7 +10,7 @@ public class GenericCommand implements Command {
/*
* The behavior for invoking the command.
*/
- private CommandHandler handler;
+ private final CommandHandler handler;
/*
* The help for the command.
@@ -30,12 +30,12 @@ public class GenericCommand implements Command {
* null, in which case the description is repeated for
* the detailed help.
*/
- public GenericCommand(CommandHandler handler, String description, String help) {
- if(handler == null) throw new NullPointerException("Command handler must not be null");
+ public GenericCommand(final CommandHandler handler, final String description, final String help) {
+ if (handler == null) throw new NullPointerException("Command handler must not be null");
this.handler = handler;
- if(description == null) {
+ if (description == null) {
this.help = new NullHelp();
} else {
this.help = new GenericHelp(description, help);
@@ -64,15 +64,15 @@ public class GenericCommand implements Command {
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
+ final StringBuilder builder = new StringBuilder();
builder.append("GenericCommand [");
- if(help != null) {
+ if (help != null) {
builder.append("help=");
builder.append(help);
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java
index 7977391..8764537 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java
@@ -1,12 +1,12 @@
package bjc.utils.cli;
-import bjc.utils.funcdata.FunctionalMap;
-import bjc.utils.funcdata.IMap;
-
import java.util.TreeMap;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
+import bjc.utils.funcdata.FunctionalMap;
+import bjc.utils.funcdata.IMap;
+
/**
* A general command mode, with a customizable set of commands
*
@@ -21,13 +21,13 @@ public class GenericCommandMode implements CommandMode {
/*
* Contains the commands this mode handles
*/
- private IMap<String, Command> commandHandlers;
- private IMap<String, Command> defaultHandlers;
+ private final IMap<String, Command> commandHandlers;
+ private final IMap<String, Command> defaultHandlers;
/*
* Contains help topics without an associated command
*/
- private IMap<String, CommandHelp> helpTopics;
+ private final IMap<String, CommandHelp> helpTopics;
/*
* The action to execute upon encountering an unknown command
@@ -37,8 +37,8 @@ public class GenericCommandMode implements CommandMode {
/*
* The functions to use for input/output
*/
- private Consumer<String> errorOutput;
- private Consumer<String> normalOutput;
+ private final Consumer<String> errorOutput;
+ private final Consumer<String> normalOutput;
/*
* The name of this command mode, or null if it is unnamed
@@ -58,10 +58,10 @@ public class GenericCommandMode implements CommandMode {
* @param errorOutput
* The function to use for error output
*/
- public GenericCommandMode(Consumer<String> normalOutput, Consumer<String> errorOutput) {
- if(normalOutput == null)
+ public GenericCommandMode(final Consumer<String> normalOutput, final Consumer<String> errorOutput) {
+ if (normalOutput == null)
throw new NullPointerException("Normal output source must be non-null");
- else if(errorOutput == null) throw new NullPointerException("Error output source must be non-null");
+ else if (errorOutput == null) throw new NullPointerException("Error output source must be non-null");
this.normalOutput = normalOutput;
this.errorOutput = errorOutput;
@@ -92,20 +92,20 @@ public class GenericCommandMode implements CommandMode {
* handler, or if the alias name already has a bound
* value
*/
- public void addCommandAlias(String commandName, String aliasName) {
- if(commandName == null)
+ public void addCommandAlias(final String commandName, final String aliasName) {
+ if (commandName == null)
throw new NullPointerException("Command name must not be null");
- else if(aliasName == null)
+ else if (aliasName == null)
throw new NullPointerException("Alias name must not be null");
- else if(!commandHandlers.containsKey(commandName) && !defaultHandlers.containsKey(commandName))
+ else if (!commandHandlers.containsKey(commandName) && !defaultHandlers.containsKey(commandName))
throw new IllegalArgumentException("Cannot alias non-existant command '" + commandName + "'");
- else if(commandHandlers.containsKey(aliasName) || defaultHandlers.containsKey(aliasName))
+ else if (commandHandlers.containsKey(aliasName) || defaultHandlers.containsKey(aliasName))
throw new IllegalArgumentException(
"Cannot bind alias '" + aliasName + "' to a command with a bound handler");
else {
Command aliasedCommand;
- if(defaultHandlers.containsKey(commandName)) {
+ if (defaultHandlers.containsKey(commandName)) {
aliasedCommand = defaultHandlers.get(commandName).aliased();
} else {
aliasedCommand = commandHandlers.get(commandName).aliased();
@@ -127,12 +127,12 @@ public class GenericCommandMode implements CommandMode {
* if the specified command already has a handler
* registered
*/
- public void addCommandHandler(String command, Command handler) {
- if(command == null)
+ public void addCommandHandler(final String command, final Command handler) {
+ if (command == null)
throw new NullPointerException("Command must not be null");
- else if(handler == null)
+ else if (handler == null)
throw new NullPointerException("Handler must not be null");
- else if(canHandle(command))
+ else if (canHandle(command))
throw new IllegalArgumentException("Command " + command + " already has a handler registered");
else {
commandHandlers.put(command, handler);
@@ -147,7 +147,7 @@ public class GenericCommandMode implements CommandMode {
* @param topic
* The contents of the topic
*/
- public void addHelpTopic(String topicName, CommandHelp topic) {
+ public void addHelpTopic(final String topicName, final CommandHelp topic) {
helpTopics.put(topicName, topic);
}
@@ -156,8 +156,8 @@ public class GenericCommandMode implements CommandMode {
*/
private GenericCommand buildAliasCommand() {
- String aliasShortHelp = "alias\tAlias one command to another";
- String aliasLongHelp = "Gives a command another name it can be invoked by."
+ final String aliasShortHelp = "alias\tAlias one command to another";
+ final String aliasLongHelp = "Gives a command another name it can be invoked by."
+ " Invoke with two arguments: the name of the command to alias"
+ "followed by the name of the alias to give that command.";
@@ -169,8 +169,8 @@ public class GenericCommandMode implements CommandMode {
}
private GenericCommand buildClearCommands() {
- String clearShortHelp = "clear\tClear the screen";
- String clearLongHelp = "Clears the screen of all the text on it," + " and prints a new prompt.";
+ final String clearShortHelp = "clear\tClear the screen";
+ final String clearLongHelp = "Clears the screen of all the text on it," + " and prints a new prompt.";
return new GenericCommand((args) -> {
errorOutput.accept("ERROR: This console doesn't support screen clearing");
@@ -180,8 +180,8 @@ public class GenericCommandMode implements CommandMode {
}
private GenericCommand buildExitCommand() {
- String exitShortHelp = "exit\tExit the console";
- String exitLongHelp = "First prompts the user to make sure they want to"
+ final String exitShortHelp = "exit\tExit the console";
+ final String exitLongHelp = "First prompts the user to make sure they want to"
+ " exit, then quits if they say they do";
return new GenericCommand((args) -> {
@@ -192,14 +192,14 @@ public class GenericCommandMode implements CommandMode {
}
private GenericCommand buildHelpCommand() {
- String helpShortHelp = "help\tConsult the help system";
- String helpLongHelp = "Consults the internal help system."
+ final String helpShortHelp = "help\tConsult the help system";
+ final String helpLongHelp = "Consults the internal help system."
+ " Invoked in two different ways. Invoking with no arguments"
+ " causes all the topics you can ask for details on to be list,"
+ " while invoking with the name of a topic will print the entry" + " for that topic";
return new GenericCommand((args) -> {
- if(args == null || args.length == 0) {
+ if (args == null || args.length == 0) {
/*
* Invoke general help
*/
@@ -216,8 +216,8 @@ public class GenericCommandMode implements CommandMode {
}
private GenericCommand buildListCommand() {
- String listShortHelp = "list\tList available commands";
- String listLongHelp = "Lists all of the commands available in this mode,"
+ final String listShortHelp = "list\tList available commands";
+ final String listLongHelp = "Lists all of the commands available in this mode,"
+ " as well as commands available in any mode";
return new GenericCommand((args) -> {
@@ -228,7 +228,7 @@ public class GenericCommandMode implements CommandMode {
}
@Override
- public boolean canHandle(String command) {
+ public boolean canHandle(final String command) {
return commandHandlers.containsKey(command) || defaultHandlers.containsKey(command);
}
@@ -236,17 +236,17 @@ public class GenericCommandMode implements CommandMode {
* Implement default commands
*/
- private void doAliasCommands(String[] args) {
- if(args.length != 2) {
+ private void doAliasCommands(final String[] args) {
+ if (args.length != 2) {
errorOutput.accept("ERROR: Alias requires two arguments."
+ " The command name, and the alias for that command");
} else {
- String commandName = args[0];
- String aliasName = args[1];
+ final String commandName = args[0];
+ final String aliasName = args[1];
- if(!canHandle(commandName)) {
+ if (!canHandle(commandName)) {
errorOutput.accept("ERROR: '" + commandName + "' is not a valid command.");
- } else if(canHandle(aliasName)) {
+ } else if (canHandle(aliasName)) {
errorOutput.accept("ERROR: Cannot overwrite command '" + aliasName + "'");
} else {
addCommandAlias(commandName, aliasName);
@@ -254,16 +254,16 @@ public class GenericCommandMode implements CommandMode {
}
}
- private void doHelpCommand(String commandName) {
- if(commandHandlers.containsKey(commandName)) {
- String desc = commandHandlers.get(commandName).getHelp().getDescription();
+ private void doHelpCommand(final String commandName) {
+ if (commandHandlers.containsKey(commandName)) {
+ final String desc = commandHandlers.get(commandName).getHelp().getDescription();
normalOutput.accept("\n" + desc);
- } else if(defaultHandlers.containsKey(commandName)) {
- String desc = defaultHandlers.get(commandName).getHelp().getDescription();
+ } else if (defaultHandlers.containsKey(commandName)) {
+ final String desc = defaultHandlers.get(commandName).getHelp().getDescription();
normalOutput.accept("\n" + desc);
- } else if(helpTopics.containsKey(commandName)) {
+ } else if (helpTopics.containsKey(commandName)) {
normalOutput.accept("\n" + helpTopics.get(commandName).getDescription());
} else {
errorOutput.accept(
@@ -274,9 +274,9 @@ public class GenericCommandMode implements CommandMode {
private void doHelpSummary() {
normalOutput.accept("Help topics for this command mode are as follows:\n");
- if(commandHandlers.size() > 0) {
+ if (commandHandlers.size() > 0) {
commandHandlers.forEachValue(command -> {
- if(!command.isAlias()) {
+ if (!command.isAlias()) {
normalOutput.accept("\t" + command.getHelp().getSummary() + "\n");
}
});
@@ -285,9 +285,9 @@ public class GenericCommandMode implements CommandMode {
}
normalOutput.accept("\nHelp topics available in all command modes are as follows\n");
- if(defaultHandlers.size() > 0) {
+ if (defaultHandlers.size() > 0) {
defaultHandlers.forEachValue(command -> {
- if(!command.isAlias()) {
+ if (!command.isAlias()) {
normalOutput.accept("\t" + command.getHelp().getSummary() + "\n");
}
});
@@ -296,7 +296,7 @@ public class GenericCommandMode implements CommandMode {
}
normalOutput.accept("\nHelp topics not associated with a command are as follows\n");
- if(helpTopics.size() > 0) {
+ if (helpTopics.size() > 0) {
helpTopics.forEachValue(topic -> {
normalOutput.accept("\t" + topic.getSummary() + "\n");
});
@@ -322,14 +322,14 @@ public class GenericCommandMode implements CommandMode {
@Override
public String getCustomPrompt() {
- if(customPrompt != null) return customPrompt;
+ if (customPrompt != null) return customPrompt;
return CommandMode.super.getCustomPrompt();
}
@Override
public String getName() {
- if(modeName != null) return modeName;
+ if (modeName != null) return modeName;
return CommandMode.super.getName();
}
@@ -340,21 +340,21 @@ public class GenericCommandMode implements CommandMode {
}
@Override
- public CommandMode process(String command, String[] args) {
+ public CommandMode process(final String command, final String[] args) {
normalOutput.accept("\n");
- if(defaultHandlers.containsKey(command))
+ if (defaultHandlers.containsKey(command))
return defaultHandlers.get(command).getHandler().handle(args);
- else if(commandHandlers.containsKey(command))
+ else if (commandHandlers.containsKey(command))
return commandHandlers.get(command).getHandler().handle(args);
else {
- if(args != null) {
+ if (args != null) {
errorOutput.accept("ERROR: Unrecognized command " + command + String.join(" ", args));
} else {
errorOutput.accept("ERROR: Unrecognized command " + command);
}
- if(unknownCommandHandler == null)
+ if (unknownCommandHandler == null)
throw new UnsupportedOperationException("Command " + command + " is invalid.");
unknownCommandHandler.accept(command, args);
@@ -370,7 +370,7 @@ public class GenericCommandMode implements CommandMode {
* The custom prompt for this mode, or null to disable
* the custom prompt
*/
- public void setCustomPrompt(String prompt) {
+ public void setCustomPrompt(final String prompt) {
customPrompt = prompt;
}
@@ -381,7 +381,7 @@ public class GenericCommandMode implements CommandMode {
* The desired name of this mode, or null to use the
* default name
*/
- public void setModeName(String name) {
+ public void setModeName(final String name) {
modeName = name;
}
@@ -392,8 +392,8 @@ public class GenericCommandMode implements CommandMode {
* The handler to use for unknown commands, or null to
* throw on unknown commands
*/
- public void setUnknownCommandHandler(BiConsumer<String, String[]> handler) {
- if(handler == null) throw new NullPointerException("Handler must not be null");
+ public void setUnknownCommandHandler(final BiConsumer<String, String[]> handler) {
+ if (handler == null) throw new NullPointerException("Handler must not be null");
unknownCommandHandler = handler;
}
@@ -424,38 +424,38 @@ public class GenericCommandMode implements CommandMode {
/*
* (non-Javadoc)
- *
+ *
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
+ final StringBuilder builder = new StringBuilder();
builder.append("GenericCommandMode [");
-
- if(commandHandlers != null) {
+
+ if (commandHandlers != null) {
builder.append("commandHandlers=");
builder.append(commandHandlers);
}
- if(defaultHandlers != null) {
+ if (defaultHandlers != null) {
builder.append(", ");
builder.append("defaultHandlers=");
builder.append(defaultHandlers);
}
- if(helpTopics != null) {
+ if (helpTopics != null) {
builder.append(", ");
builder.append("helpTopics=");
builder.append(helpTopics);
}
- if(modeName != null) {
+ if (modeName != null) {
builder.append(", ");
builder.append("modeName=");
builder.append(modeName);
}
- if(customPrompt != null) {
+ if (customPrompt != null) {
builder.append(", ");
builder.append("customPrompt=");
builder.append(customPrompt);
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java
index edda5c0..38adf57 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java
@@ -8,8 +8,8 @@ package bjc.utils.cli;
*/
public class GenericHelp implements CommandHelp {
// The strings for this help topic
- private String summary;
- private String description;
+ private final String summary;
+ private final String description;
/**
* Create a new help topic
@@ -20,8 +20,8 @@ public class GenericHelp implements CommandHelp {
* The description of this help topic, or null if this
* help topic doesn't have a more detailed description
*/
- public GenericHelp(String summary, String description) {
- if(summary == null) throw new NullPointerException("Help summary must be non-null");
+ public GenericHelp(final String summary, final String description) {
+ if (summary == null) throw new NullPointerException("Help summary must be non-null");
this.summary = summary;
this.description = description;
@@ -29,7 +29,7 @@ public class GenericHelp implements CommandHelp {
@Override
public String getDescription() {
- if(description == null) return summary;
+ if (description == null) return summary;
return description;
}
@@ -41,23 +41,23 @@ public class GenericHelp implements CommandHelp {
@Override
public String toString() {
- StringBuilder builder = new StringBuilder();
-
+ final StringBuilder builder = new StringBuilder();
+
builder.append("GenericHelp [");
-
- if(summary != null) {
+
+ if (summary != null) {
builder.append("summary=");
builder.append(summary);
}
-
- if(description != null) {
+
+ if (description != null) {
builder.append(", ");
builder.append("description=");
builder.append(description);
}
-
+
builder.append("]");
-
+
return builder.toString();
}
}
diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/NullHelp.java b/BJC-Utils2/src/main/java/bjc/utils/cli/NullHelp.java
index 289d9c1..6c49ae6 100644
--- a/BJC-Utils2/src/main/java/bjc/utils/cli/NullHelp.java
+++ b/BJC-Utils2/src/main/java/bjc/utils/cli/NullHelp.java
@@ -16,6 +16,5 @@ public class NullHelp implements CommandHelp {
public String getSummary() {
return "No summary provided";
}
-
-
+
}