diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-10-21 14:14:48 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-10-21 14:14:48 -0400 |
| commit | 5cf7bcf156970fe72f79e40b8a6e320ea160ac83 (patch) | |
| tree | 52bba3b684c493c726538194b5965150abb4a786 /BJC-Utils2/src/main/java/bjc/utils/cli | |
| parent | b0516949d7577b809c75d7267df77bff2cdb078b (diff) | |
Documentation
Diffstat (limited to 'BJC-Utils2/src/main/java/bjc/utils/cli')
6 files changed, 51 insertions, 10 deletions
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 e73d936..54d2fa0 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java +++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommand.java @@ -1,5 +1,7 @@ package bjc.utils.cli; +import org.eclipse.jdt.annotation.Nullable; + /** * Generic command implementation * @@ -18,19 +20,24 @@ public class GenericCommand implements ICommand { * @param handler * The handler to use for the command * @param description - * The description of the command + * The description of the command. May be null * @param help - * The detailed help message for the command + * The detailed help message for the command. May be null */ - public GenericCommand(ICommandHandler handler, String description, - String help) { + public GenericCommand(ICommandHandler handler, @Nullable String description, + @Nullable String help) { if (handler == null) { throw new NullPointerException( "Command handler must not be null"); } this.handler = handler; - this.help = new GenericHelp(description, help); + + if (description == null) { + this.help = new NullHelp(); + } else { + this.help = new GenericHelp(description, help); + } } @Override 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 4b3b4fd..4aab8a4 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java +++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericCommandMode.java @@ -7,6 +7,8 @@ import java.util.function.Consumer; import bjc.utils.funcdata.FunctionalMap; import bjc.utils.funcdata.IMap; +import org.eclipse.jdt.annotation.Nullable; + /** * A general command mode, with a customizable set of commands * @@ -50,6 +52,14 @@ public class GenericCommandMode implements ICommandMode { */ public GenericCommandMode(Consumer<String> normalOutput, 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"); + } + this.normalOutput = normalOutput; this.errorOutput = errorOutput; @@ -371,7 +381,7 @@ public class GenericCommandMode implements ICommandMode { * The custom prompt for this mode, or null to disable the * custom prompt */ - public void setCustomPrompt(String prompt) { + public void setCustomPrompt(@Nullable String prompt) { customPrompt = prompt; } @@ -382,7 +392,7 @@ public class GenericCommandMode implements ICommandMode { * The desired name of this mode, or null to use the default * name */ - public void setModeName(String name) { + public void setModeName(@Nullable String name) { modeName = name; } @@ -394,7 +404,7 @@ public class GenericCommandMode implements ICommandMode { * on unknown commands */ public void setUnknownCommandHandler( - BiConsumer<String, String[]> handler) { + @Nullable BiConsumer<String, String[]> handler) { if (handler == null) { throw new NullPointerException("Handler must not be null"); } 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 8742b5d..2e46202 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java +++ b/BJC-Utils2/src/main/java/bjc/utils/cli/GenericHelp.java @@ -1,5 +1,7 @@ package bjc.utils.cli; +import org.eclipse.jdt.annotation.Nullable; + /** * Generic implementation of a help topic * @@ -20,7 +22,7 @@ public class GenericHelp implements ICommandHelp { * 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) { + public GenericHelp(String summary, @Nullable String description) { if (summary == null) { throw new NullPointerException( "Help summary must be non-null"); diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java index 3d451a7..33182b3 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java +++ b/BJC-Utils2/src/main/java/bjc/utils/cli/ICommandHandler.java @@ -8,6 +8,7 @@ import java.util.function.Function; * @author ben * */ +@FunctionalInterface public interface ICommandHandler extends Function<String[], ICommandMode> { /** * Execute this command diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/NullHelp.java b/BJC-Utils2/src/main/java/bjc/utils/cli/NullHelp.java new file mode 100644 index 0000000..e150ba6 --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/cli/NullHelp.java @@ -0,0 +1,20 @@ +package bjc.utils.cli; + +/** + * Implementation of a help topic that doesn't exist + * + * @author ben + * + */ +public class NullHelp implements ICommandHelp { + + @Override + public String getDescription() { + return "No description provided"; + } + + @Override + public String getSummary() { + return "No summary provided"; + } +}
\ No newline at end of file diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/package-info.java b/BJC-Utils2/src/main/java/bjc/utils/cli/package-info.java index a87aa24..1bdfd14 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/cli/package-info.java +++ b/BJC-Utils2/src/main/java/bjc/utils/cli/package-info.java @@ -4,4 +4,5 @@ * @author ben * */ -package bjc.utils.cli;
\ No newline at end of file +@org.eclipse.jdt.annotation.NonNullByDefault +package bjc.utils.cli; |
