diff options
Diffstat (limited to 'base/src/main/java/bjc/utils/cli')
9 files changed, 361 insertions, 428 deletions
diff --git a/base/src/main/java/bjc/utils/cli/Command.java b/base/src/main/java/bjc/utils/cli/Command.java index 7451cf7..68351bf 100644 --- a/base/src/main/java/bjc/utils/cli/Command.java +++ b/base/src/main/java/bjc/utils/cli/Command.java @@ -7,13 +7,6 @@ package bjc.utils.cli; */ public interface Command { /** - * Create a command that serves as an alias to this one - * - * @return A command that serves as an alias to this one - */ - Command aliased(); - - /** * Get the handler that executes this command * * @return The handler that executes this command @@ -26,7 +19,16 @@ public interface Command { * @return The help entry for this command */ CommandHelp getHelp(); - + + /** + * Create a command that serves as an alias to this one + * + * @return A command that serves as an alias to this one + */ + default Command aliased() { + return new DelegatingCommand(this); + }; + /** * Check if this command is an alias of another command * @@ -35,4 +37,21 @@ public interface Command { default boolean isAlias() { return false; } + + /** + * Create a new basic command. + * + * @param summary The summary of the command. This is used as a short help + * message displayed when listing commands. + * @param description The description of the command. This is what is shown + * when the detailed help for a command is asked for. + * @param handler The implementation for the command. + * + * @return A command with the given implementation. + */ + static Command from( + String summary, String description, CommandHandler handler) + { + return new GenericCommand(handler, summary, description); + } } diff --git a/base/src/main/java/bjc/utils/cli/DelegatingCommand.java b/base/src/main/java/bjc/utils/cli/DelegatingCommand.java index f17b6b5..fa2d1db 100644 --- a/base/src/main/java/bjc/utils/cli/DelegatingCommand.java +++ b/base/src/main/java/bjc/utils/cli/DelegatingCommand.java @@ -21,6 +21,7 @@ class DelegatingCommand implements Command { @Override public Command aliased() { + // Prevent double-indirections return new DelegatingCommand(delegate); } diff --git a/base/src/main/java/bjc/utils/cli/GenericCommand.java b/base/src/main/java/bjc/utils/cli/GenericCommand.java index a847bea..6903152 100644 --- a/base/src/main/java/bjc/utils/cli/GenericCommand.java +++ b/base/src/main/java/bjc/utils/cli/GenericCommand.java @@ -12,40 +12,25 @@ public class GenericCommand implements Command { /* The help for the command. */ private CommandHelp help; - /** - * Create a new generic command. + /** Create a new generic command. * - * @param handler - * The handler to use for the command. - * - * @param description - * The description of the command. May be null, in which case - * a default is provided. - * - * @param help - * The detailed help message for the command. May be null, in - * which case the description is repeated for the detailed - * help. - */ - public GenericCommand(final CommandHandler handler, final String description, - final String help) { + * @param handler The handler to use for the command. + * @param summary The summary of the command. May be null, in which case a + * default is provided. + * @param description The detailed help message for the command. May be null, + * in which case the summary is repeated for the + * detailed help. */ + public GenericCommand(final CommandHandler handler, final String summary, + final String description) { if (handler == null) throw new NullPointerException("Command handler must not be null"); this.handler = handler; - if (description == null) { - this.help = new NullHelp(); - } else { - this.help = new GenericHelp(description, help); - } - } - - @Override - public Command aliased() { - return new DelegatingCommand(this); + if (summary == null) this.help = new NullHelp(); + else this.help = new GenericHelp(summary, description); } - + @Override public CommandHandler getHandler() { return handler; @@ -57,16 +42,6 @@ public class GenericCommand implements Command { } @Override - public boolean isAlias() { - return false; - } - - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ - @Override public String toString() { return String.format("GenericCommand [help=%s]", help); } diff --git a/base/src/main/java/bjc/utils/cli/GenericCommandMode.java b/base/src/main/java/bjc/utils/cli/GenericCommandMode.java index 328bbee..3642137 100644 --- a/base/src/main/java/bjc/utils/cli/GenericCommandMode.java +++ b/base/src/main/java/bjc/utils/cli/GenericCommandMode.java @@ -5,7 +5,7 @@ import java.util.function.BiConsumer; import java.util.function.Consumer; import bjc.funcdata.FunctionalMap; -import bjc.funcdata.IMap; +import bjc.funcdata.MapEx; /** * A general command mode, with a customizable set of commands. @@ -18,12 +18,12 @@ import bjc.funcdata.IMap; */ public class GenericCommandMode implements CommandMode { /* Contains the commands this mode handles. */ - private final IMap<String, Command> commandHandlers; + private final MapEx<String, Command> commandHandlers; /* Commands to execute in every mode. */ - private final IMap<String, Command> defaultHandlers; + private final MapEx<String, Command> defaultHandlers; /* Contains help topics without an associated command */ - private final IMap<String, CommandHelp> helpTopics; + private final MapEx<String, CommandHelp> helpTopics; /* The action to execute upon encountering an unknown command */ private BiConsumer<String, String[]> unknownCommandHandler; @@ -55,12 +55,12 @@ public class GenericCommandMode implements CommandMode { throw new NullPointerException("Error output source must be non-null"); this.normalOutput = normalOutput; - this.errorOutput = errorOutput; + this.errorOutput = errorOutput; /* Initialize maps so that they sort in alphabetical order. */ commandHandlers = new FunctionalMap<>(new TreeMap<>()); defaultHandlers = new FunctionalMap<>(new TreeMap<>()); - helpTopics = new FunctionalMap<>(new TreeMap<>()); + helpTopics = new FunctionalMap<>(new TreeMap<>()); /* Setup default commands. */ setupDefaultCommands(); @@ -84,17 +84,16 @@ public class GenericCommandMode implements CommandMode { if (commandName == null) { throw new NullPointerException("Command name must not be null"); } else if (aliasName == null) { - String msg = "Alias name must not be null"; - throw new NullPointerException(msg); + throw new NullPointerException("Alias name must not be null"); } else if (!commandHandlers.containsKey(commandName) && !defaultHandlers.containsKey(commandName)) { - String msg = String.format("Cannot alias non-existant command '%s'", + String msg = String.format("Cannot alias non-existing command '%s'", commandName); throw new IllegalArgumentException(msg); } else if (commandHandlers.containsKey(aliasName) || defaultHandlers.containsKey(aliasName)) { String msg = String.format( - "Cannot bind alias '%s' to an already bound command.", aliasName); + "Cannot bind alias '%s' to an already used name.", aliasName); throw new IllegalArgumentException(msg); } else { /* The command that will be aliased. */ @@ -102,9 +101,9 @@ public class GenericCommandMode implements CommandMode { /* Get the alias. */ if (defaultHandlers.containsKey(commandName)) { - aliasedCommand = defaultHandlers.get(commandName).aliased(); + aliasedCommand = defaultHandlers.get(commandName).get().aliased(); } else { - aliasedCommand = commandHandlers.get(commandName).aliased(); + aliasedCommand = commandHandlers.get(commandName).get().aliased(); } commandHandlers.put(aliasName, aliasedCommand); @@ -262,16 +261,16 @@ public class GenericCommandMode implements CommandMode { private void doHelpCommand(final String commandName) { if (commandHandlers.containsKey(commandName)) { final String desc - = commandHandlers.get(commandName).getHelp().getDescription(); + = commandHandlers.get(commandName).get().getHelp().getDescription(); normalOutput.accept("\n" + desc); } else if (defaultHandlers.containsKey(commandName)) { final String desc - = defaultHandlers.get(commandName).getHelp().getDescription(); + = defaultHandlers.get(commandName).get().getHelp().getDescription(); normalOutput.accept("\n" + desc); } else if (helpTopics.containsKey(commandName)) { - normalOutput.accept("\n" + helpTopics.get(commandName).getDescription()); + normalOutput.accept("\n" + helpTopics.get(commandName).get().getDescription()); } else { String msg = String.format("ERROR: No help available for '%s'", commandName); @@ -371,9 +370,9 @@ public class GenericCommandMode implements CommandMode { normalOutput.accept("\n"); if (defaultHandlers.containsKey(command)) - return defaultHandlers.get(command).getHandler().handle(args); + return defaultHandlers.get(command).get().getHandler().handle(args); else if (commandHandlers.containsKey(command)) - return commandHandlers.get(command).getHandler().handle(args); + return commandHandlers.get(command).get().getHandler().handle(args); else { if (args != null) { String argString = String.join(", ", args); diff --git a/base/src/main/java/bjc/utils/cli/GenericHelp.java b/base/src/main/java/bjc/utils/cli/GenericHelp.java index 45d3a88..0157d4f 100644 --- a/base/src/main/java/bjc/utils/cli/GenericHelp.java +++ b/base/src/main/java/bjc/utils/cli/GenericHelp.java @@ -1,17 +1,14 @@ package bjc.utils.cli; -/** - * Generic implementation of a help topic. +/** Generic implementation of a help topic. * - * @author ben - */ + * @author ben */ public class GenericHelp implements CommandHelp { /* The strings for this help topic. */ private final String summary; private final String description; - /** - * Create a new help topic. + /** Create a new help topic. * * @param summary * The summary of this help topic. @@ -31,9 +28,7 @@ public class GenericHelp implements CommandHelp { @Override public String getDescription() { - if (description == null) { - return summary; - } + if (description == null) return summary; return description; } diff --git a/base/src/main/java/bjc/utils/cli/NullHelp.java b/base/src/main/java/bjc/utils/cli/NullHelp.java index 5e5fb67..048b6e7 100644 --- a/base/src/main/java/bjc/utils/cli/NullHelp.java +++ b/base/src/main/java/bjc/utils/cli/NullHelp.java @@ -1,10 +1,8 @@ package bjc.utils.cli; -/** - * Implementation of a help topic that doesn't exist. +/** Implementation of a help topic that doesn't exist or isn't provided. * - * @author ben - */ + * @author ben */ public class NullHelp implements CommandHelp { @Override public String getDescription() { @@ -15,5 +13,4 @@ public class NullHelp implements CommandHelp { public String getSummary() { return "No summary provided"; } - -} +}
\ No newline at end of file diff --git a/base/src/main/java/bjc/utils/cli/objects/Command.java b/base/src/main/java/bjc/utils/cli/objects/Command.java index af22643..3b287ea 100644 --- a/base/src/main/java/bjc/utils/cli/objects/Command.java +++ b/base/src/main/java/bjc/utils/cli/objects/Command.java @@ -3,341 +3,288 @@ package bjc.utils.cli.objects; import java.util.regex.Matcher; import java.util.regex.Pattern; -/** - * A single-line command read from the user. +/** A single-line command read from the user. * - * @author Ben Culkin - */ + * @author Ben Culkin */ public class Command { - /** - * Command status values. - * - * @author Ben Culkin - */ - public static enum CommandStatus { - /** - * The command succeeded. - */ - SUCCESS, - /** - * The command failed non-fatally. - */ - FAIL, - /** - * The command failed fatally. - */ - ERROR, - /** - * The command was the last one. - */ - FINISH, - } - - /** - * The line number of this command. - */ - public final int lno; - - /** - * The full text of this command. - */ - public final String full; - /** - * The text of this command without its name. - */ - public String remn; - /** - * The name of this command. - */ - public final String name; - - /** - * The name of the I/O source this command was read from. - */ - public final String src; - - /** - * Create a new command. - * - * @param ln - * The string to get the command from. - * - * @param lno - * The number of the line the command came from. - * - * @param ioSrc - * The name of where the I/O came from. - */ - public Command(String ln, int lno, String ioSrc) { - int idx = ln.indexOf(' '); - - if (idx == -1) - idx = ln.length(); - - /* Grab command parts. */ - full = ln; - name = ln.substring(0, idx).trim(); - remn = ln.substring(idx).trim(); - - this.lno = lno; - - src = ioSrc; - } - - /** - * Removes up until the first occurrence of a particular string for the - * remaining command, and returns the removed string. - * - * By default, both the substring and the remaining text are trimmed - * (leading/trailing spaces removed). - * - * @param delm - * The delimiter to stop substringing at. - * - * @return The substring, or null if there is no occurrence of the delimiter. - */ - public String trimTo(String delm) { - return trimTo(delm, true); - } - - /** - * Removes up until the first occurrence of a particular string for the - * remaining command, and returns the removed string. - * - * @param delm - * The delimiter to stop substringing at. - * @param doTrim - * Whether or not to trim the substring and remaining command - * (Remove leading/trailing spaces). - * - * @return The substring, or null if there is no occurrence of the delimiter. - */ - public String trimTo(String delm, boolean doTrim) { - int idx = remn.indexOf(delm); - if (idx == -1) - return null; - - String tmp = remn.substring(0, idx); - remn = remn.substring(idx); - - if (doTrim) { - tmp = tmp.trim(); - remn = remn.trim(); - } - - return tmp; - } - - /** - * Removes up until the first occurrence of a particular regex for the remaining - * command, and returns the removed string. - * - * By default, both the substring and the remaining text are trimmed - * (leading/trailing spaces removed). - * - * @param rDelm - * The regex to stop substringing at. - * - * @return The string, up to the matched pattern. - */ - public String trimToRX(String rDelm) { - return trimToRX(Pattern.compile(rDelm), true); - } - - /** - * Removes up until the first occurrence of a particular regex for the remaining - * command, and returns the removed string. - * - * By default, both the substring and the remaining text are trimmed - * (leading/trailing spaces removed). - * - * @param delm - * The regex to stop substringing at. - * - * @return The string, up to the matched pattern. - */ - public String trimToRX(Pattern delm) { - return trimToRX(delm, true); - } - - /** - * Removes up until the first occurrence of a particular regex for the remaining - * command, and returns the removed string. - * - * @param rDelm - * The regex to stop substringing at. - * @param doTrim - * Whether or not to trim the substring and remaining command - * (Remove leading/trailing spaces). - * - * @return The string, up to the matched pattern. - */ - public String trimToRX(String rDelm, boolean doTrim) { - return trimToRX(Pattern.compile(rDelm), doTrim); - } - - /** - * Removes up until the first occurrence of a particular regex for the remaining - * command, and returns the removed string. - * - * @param delm - * The regex to stop substringing at. - * @param doTrim - * Whether or not to trim the substring and remaining command - * (Remove leading/trailing spaces). - * - * @return The string, up to the matched pattern. - */ - public String trimToRX(Pattern delm, boolean doTrim) { - Matcher mat = delm.matcher(remn); - if (!mat.find()) - return null; - - String tmp = remn.substring(0, mat.start()); - remn = remn.substring(mat.end()); - - if (doTrim) { - tmp = tmp.trim(); - remn = remn.trim(); - } - - return tmp; - } - - /** - * Removes up until the first occurrence of a particular string for the - * remaining command, and returns the removed string. - * - * By default, both the substring and the remaining text are trimmed - * (leading/trailing spaces removed). - * - * @param delm - * The delimiter to stop substringing at. - * - * @return The substring, or null if there is no occurrence of the delimiter. - */ - public String trimTo(char delm) { - return trimTo(delm, true); - } - - /** - * Removes up until the first occurrence of a particular string for the - * remaining command, and returns the removed string. - * - * @param delm - * The delimiter to stop substringing at. - * @param doTrim - * Whether or not to trim the substring and remaining command - * (Remove leading/trailing spaces). - * - * @return The substring, or null if there is no occurrence of the delimiter. - */ - public String trimTo(char delm, boolean doTrim) { - int idx = remn.indexOf(delm); - if (idx == -1) - return null; - - String tmp = remn.substring(0, idx); - remn = remn.substring(idx); - - if (doTrim) { - tmp = tmp.trim(); - remn = remn.trim(); - } - - return tmp; - } - - /** - * Check if this command has text after its name. - * - * @return Whether or not this command has text after its name. - */ - public boolean hasRemaining() { - return !remn.equals(""); - } - - /** - * Parse a command from a string. - * - * The main thing this does is ignore blank lines, as well as comments marked by - * #'s either at the start of the line or part of the way through the line. - * - * @param lne - * The string to get the command from. - * - * @param lno - * The line number of the command. - * - * @param srcName - * The name of where the I/O came from. - * @return The parsed command - */ - public static Command fromString(String lne, int lno, String srcName) { - String ln = lne; - - /* Ignore blank lines and comments. */ - if (ln.equals("")) - return null; - if (ln.startsWith("#")) - return null; - - /* Trim off comments part-way through the line. */ - int idxHash = ln.indexOf('#'); - if (idxHash != -1) { - ln = ln.substring(0, idxHash).trim(); - } - - return new Command(ln, lno, srcName); - } - - /** - * Give an informational message about something in relation to this command. - * - * @param info - * The informational message. - * - * @param parms - * The parameters for the informational message. - * @return The information message. - */ - public String info(String info, Object... parms) { - String msg = String.format(info, parms); - - return String.format("INFO (%s:%d): %s", src, lno, msg); - } - - /** - * Warn about something in relation to this command. - * - * @param warning - * The warning message. - * - * @param parms - * The parameters for the warning message. - * - * @return The formatted warning. - */ - public String warn(String warning, Object... parms) { - String msg = String.format(warning, parms); - - return String.format("WARNING (%s:%d): %s", src, lno, msg); - } - - /** - * Give an error about something in relation to this command. - * - * @param err - * The error message. - * - * @param parms - * The parameters for the error message. - * - * @return The formatted error - */ - public String error(String err, Object... parms) { - String msg = String.format(err, parms); - - return String.format("ERROR (%s:%d): %s", src, lno, msg); - } -} + /** Command status values. + * + * @author Ben Culkin */ + public static enum CommandStatus { + /** The command succeeded. */ + SUCCESS, + /** The command failed non-fatally. */ + FAIL, + /** The command failed fatally. */ + ERROR, + /** The command was the last one. */ + FINISH, + } + + /** The line number of this command. */ + public final int lno; + + /** The full text of this command. */ + public final String full; + /** The text of this command without its name. */ + public String remn; + /** The name of this command. */ + public final String name; + + /** The name of the I/O source this command was read from. */ + public final String src; + + /** Create a new command. + * + * @param ln + * The string to get the command from. + * + * @param lno + * The number of the line the command came from. + * + * @param ioSrc + * The name of where the I/O came from. */ + public Command(String ln, int lno, String ioSrc) { + int idx = ln.indexOf(' '); + if (idx == -1) idx = ln.length(); + + /* Grab command parts. */ + full = ln; + name = ln.substring(0, idx).trim(); + remn = ln.substring(idx).trim(); + + this.lno = lno; + + src = ioSrc; + } + + /** Removes up until the first occurrence of a particular string for the + * remaining command, and returns the removed string. + * + * By default, both the substring and the remaining text are trimmed + * (leading/trailing spaces removed). + * + * @param delm + * The delimiter to stop substringing at. + * + * @return The substring, or null if there is no occurrence of the delimiter. */ + public String trimTo(String delm) { + return trimTo(delm, true); + } + + /** Removes up until the first occurrence of a particular string for the + * remaining command, and returns the removed string. + * + * @param delm + * The delimiter to stop substringing at. + * @param doTrim + * Whether or not to trim the substring and remaining command + * (Remove leading/trailing spaces). + * + * @return The substring, or null if there is no occurrence of the delimiter. */ + public String trimTo(String delm, boolean doTrim) { + int idx = remn.indexOf(delm); + if (idx == -1) return null; + + String tmp = remn.substring(0, idx); + remn = remn.substring(idx); + + if (doTrim) { + tmp = tmp.trim(); + remn = remn.trim(); + } + + return tmp; + } + + /** Removes up until the first occurrence of a particular regex for the + * remaining + * command, and returns the removed string. + * + * By default, both the substring and the remaining text are trimmed + * (leading/trailing spaces removed). + * + * @param rDelm + * The regex to stop substringing at. + * + * @return The string, up to the matched pattern. */ + public String trimToRX(String rDelm) { + return trimToRX(Pattern.compile(rDelm), true); + } + + /** Removes up until the first occurrence of a particular regex for the + * remaining + * command, and returns the removed string. + * + * By default, both the substring and the remaining text are trimmed + * (leading/trailing spaces removed). + * + * @param delm + * The regex to stop substringing at. + * + * @return The string, up to the matched pattern. */ + public String trimToRX(Pattern delm) { + return trimToRX(delm, true); + } + + /** Removes up until the first occurrence of a particular regex for the + * remaining + * command, and returns the removed string. + * + * @param rDelm + * The regex to stop substringing at. + * @param doTrim + * Whether or not to trim the substring and remaining command + * (Remove leading/trailing spaces). + * + * @return The string, up to the matched pattern. */ + public String trimToRX(String rDelm, boolean doTrim) { + return trimToRX(Pattern.compile(rDelm), doTrim); + } + + /** Removes up until the first occurrence of a particular regex for the + * remaining + * command, and returns the removed string. + * + * @param delm + * The regex to stop substringing at. + * @param doTrim + * Whether or not to trim the substring and remaining command + * (Remove leading/trailing spaces). + * + * @return The string, up to the matched pattern. */ + public String trimToRX(Pattern delm, boolean doTrim) { + Matcher mat = delm.matcher(remn); + if (!mat.find()) return null; + + String tmp = remn.substring(0, mat.start()); + remn = remn.substring(mat.end()); + + if (doTrim) { + tmp = tmp.trim(); + remn = remn.trim(); + } + + return tmp; + } + + /** Removes up until the first occurrence of a particular string for the + * remaining command, and returns the removed string. + * + * By default, both the substring and the remaining text are trimmed + * (leading/trailing spaces removed). + * + * @param delm + * The delimiter to stop substringing at. + * + * @return The substring, or null if there is no occurrence of the delimiter. */ + public String trimTo(char delm) { + return trimTo(delm, true); + } + + /** Removes up until the first occurrence of a particular string for the + * remaining command, and returns the removed string. + * + * @param delm + * The delimiter to stop substringing at. + * @param doTrim + * Whether or not to trim the substring and remaining command + * (Remove leading/trailing spaces). + * + * @return The substring, or null if there is no occurrence of the delimiter. */ + public String trimTo(char delm, boolean doTrim) { + int idx = remn.indexOf(delm); + if (idx == -1) return null; + + String tmp = remn.substring(0, idx); + remn = remn.substring(idx); + + if (doTrim) { + tmp = tmp.trim(); + remn = remn.trim(); + } + + return tmp; + } + + /** Check if this command has text after its name. + * + * @return Whether or not this command has text after its name. */ + public boolean hasRemaining() { + return !remn.equals(""); + } + + /** Parse a command from a string. + * + * The main thing this does is ignore blank lines, as well as comments marked by + * #'s either at the start of the line or part of the way through the line. + * + * @param lne + * The string to get the command from. + * + * @param lno + * The line number of the command. + * + * @param srcName + * The name of where the I/O came from. + * + * @return The parsed command */ + public static Command fromString(String lne, int lno, String srcName) { + String ln = lne; + + /* Ignore blank lines and comments. */ + if (ln.equals("")) return null; + if (ln.startsWith("#")) return null; + + /* Trim off comments part-way through the line. */ + int idxHash = ln.indexOf('#'); + if (idxHash != -1) ln = ln.substring(0, idxHash).trim(); + + return new Command(ln, lno, srcName); + } + + /** Give an informational message about something in relation to this command. + * + * @param info + * The informational message. + * + * @param parms + * The parameters for the informational message. + * + * @return The information message. */ + public String info(String info, Object... parms) { + String msg = String.format(info, parms); + + return String.format("INFO (%s:%d): %s", src, lno, msg); + } + + /** Warn about something in relation to this command. + * + * @param warning + * The warning message. + * + * @param parms + * The parameters for the warning message. + * + * @return The formatted warning. */ + public String warn(String warning, Object... parms) { + String msg = String.format(warning, parms); + + return String.format("WARNING (%s:%d): %s", src, lno, msg); + } + + /** Give an error about something in relation to this command. + * + * @param err + * The error message. + * + * @param parms + * The parameters for the error message. + * + * @return The formatted error */ + public String error(String err, Object... parms) { + String msg = String.format(err, parms); + + return String.format("ERROR (%s:%d): %s", src, lno, msg); + } +}
\ No newline at end of file diff --git a/base/src/main/java/bjc/utils/cli/objects/DefineCLI.java b/base/src/main/java/bjc/utils/cli/objects/DefineCLI.java index d2595d6..613b223 100644 --- a/base/src/main/java/bjc/utils/cli/objects/DefineCLI.java +++ b/base/src/main/java/bjc/utils/cli/objects/DefineCLI.java @@ -14,7 +14,7 @@ import java.util.logging.Logger; import java.util.regex.Pattern; import bjc.utils.cli.objects.Command.CommandStatus; -import bjc.utils.funcutils.StringUtils; +import bjc.utils.parserutils.*; /* * @TODO 10/09/17 :DefineCLIFinish @@ -130,7 +130,7 @@ public class DefineCLI { } private CommandStatus defString(Command com) { - List<String> arguments = StringUtils.processArguments(com.remn); + List<String> arguments = TokenUtils.processArguments(com.remn); if (arguments.size() < 1) { LOGGER.severe(com.error( @@ -158,7 +158,7 @@ public class DefineCLI { } private CommandStatus defFormat(Command com) { - List<String> arguments = StringUtils.processArguments(com.remn); + List<String> arguments = TokenUtils.processArguments(com.remn); if (arguments.size() < 1) { LOGGER.severe(com.error( @@ -186,7 +186,7 @@ public class DefineCLI { } private CommandStatus bindFormat(Command com) { - List<String> strings = StringUtils.processArguments(com.remn); + List<String> strings = TokenUtils.processArguments(com.remn); if (strings.size() < 2) { LOGGER.severe(com.error( diff --git a/base/src/main/java/bjc/utils/cli/objects/DelimSplitterCLI.java b/base/src/main/java/bjc/utils/cli/objects/DelimSplitterCLI.java index a6820f2..53d6d1e 100644 --- a/base/src/main/java/bjc/utils/cli/objects/DelimSplitterCLI.java +++ b/base/src/main/java/bjc/utils/cli/objects/DelimSplitterCLI.java @@ -10,9 +10,9 @@ import java.util.List; import java.util.Map; import java.util.Scanner; -import bjc.data.ITree; +import bjc.data.Tree; import bjc.funcdata.FunctionalList; -import bjc.funcdata.IList; +import bjc.funcdata.ListEx; import bjc.utils.funcutils.StringUtils; import bjc.utils.ioutils.MirrorDB; import bjc.utils.parserutils.delims.DelimiterException; @@ -359,7 +359,7 @@ public class DelimSplitterCLI { private void handleDelim(final String args) { try { - final ITree<String> res = dlm.delimitSequence(args.split(" ")); + final Tree<String> res = dlm.delimitSequence(args.split(" ")); printDelimSeq(res); } catch (final DelimiterException dex) { @@ -372,14 +372,14 @@ public class DelimSplitterCLI { for (int i = 0; i < argArray.length; i++) { final String arg = argArray[i]; - final IList<String> strangs = split.split(arg); + final ListEx<String> strangs = split.split(arg); System.out.printf("%d '%s' %s\n", i, arg, strangs); } } private void handleTest(final String inp, final boolean splitWS) { - IList<String> strings; + ListEx<String> strings; try { strings = split.split(inp); @@ -400,7 +400,7 @@ public class DelimSplitterCLI { strings = new FunctionalList<>(tks); } try { - final ITree<String> delim + final Tree<String> delim = dlm.delimitSequence(strings.toArray(new String[0])); printDelimSeq(delim); @@ -410,7 +410,7 @@ public class DelimSplitterCLI { } } - private void printDelimSeq(final ITree<String> delim) { + private void printDelimSeq(final Tree<String> delim) { System.out.println("Delimited tokens:\n" + delim.getChild(1).toString()); System.out.print("Delimited expr: "); printDelimTree(delim); @@ -420,7 +420,7 @@ public class DelimSplitterCLI { System.out.println(); } - private void printDelimTree(final ITree<String> tree) { + private void printDelimTree(final Tree<String> tree) { final StringBuilder sb = new StringBuilder(); intPrintDelimTree(tree.getChild(1), sb); @@ -428,13 +428,13 @@ public class DelimSplitterCLI { System.out.println(sb.toString().replaceAll("\\s+", " ")); } - private void intPrintDelimTree(final ITree<String> tree, final StringBuilder sb) { + private void intPrintDelimTree(final Tree<String> tree, final StringBuilder sb) { tree.doForChildren(child -> { intPrintDelimNode(child, sb); }); } - private void intPrintDelimNode(final ITree<String> tree, final StringBuilder sb) { + private void intPrintDelimNode(final Tree<String> tree, final StringBuilder sb) { if (tree.getHead().equals("contents")) { intPrintDelimTree(tree, sb); return; @@ -458,7 +458,7 @@ public class DelimSplitterCLI { case 3: intPrintDelimNode(tree.getChild(0), sb); - final ITree<String> contents = tree.getChild(1); + final Tree<String> contents = tree.getChild(1); intPrintDelimTree(contents.getChild(0), sb); intPrintDelimNode(tree.getChild(2), sb); |
