From daceafeeb90680116c289a7c301c42eb3e57eb97 Mon Sep 17 00:00:00 2001 From: bjculkin Date: Tue, 28 Mar 2017 16:48:43 -0400 Subject: Mostly finish FDS core The major changes this time are that we have both data/command macros, as well as proper Unicode character support. --- .../main/java/bjc/utils/cli/fds/SimpleFDSMode.java | 73 +++++++++++++++------- 1 file changed, 49 insertions(+), 24 deletions(-) (limited to 'BJC-Utils2/src/main/java/bjc/utils/cli/fds/SimpleFDSMode.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/cli/fds/SimpleFDSMode.java b/BJC-Utils2/src/main/java/bjc/utils/cli/fds/SimpleFDSMode.java index 1dceb3a..8854d8e 100644 --- a/BJC-Utils2/src/main/java/bjc/utils/cli/fds/SimpleFDSMode.java +++ b/BJC-Utils2/src/main/java/bjc/utils/cli/fds/SimpleFDSMode.java @@ -22,14 +22,16 @@ import static java.lang.String.format; * The FDS state type. */ public class SimpleFDSMode implements FDSMode { - private Map> commands; - private Map> modes; - private Multimap help; + private Map> commands; + private Map> modes; + private Multimap help; - private Set registered; - private char[] registeredArray; + private Set registered; + private String[] registeredArray; private boolean changed; + private String modeName; + /** * Create a new empty FDS mode. */ @@ -42,6 +44,26 @@ public class SimpleFDSMode implements FDSMode { changed = true; } + /** + * Create a new empty mode with a given name. + * + * @param name + * The name of the mode. + */ + public SimpleFDSMode(String name) { + this(); + + modeName = name; + } + + @Override + public String getName() { + if(modeName == null) + return FDSMode.super.getName(); + else + return modeName; + } + /** * Add a command to the mode. * @@ -57,17 +79,17 @@ public class SimpleFDSMode implements FDSMode { * @throws IllegalArgumentException * If the character is already bound to a command. */ - public void addCommand(char c, FDSCommand comm, CommandHelp hlp) { - if (comm == null) + public void addCommand(String c, FDSCommand comm, CommandHelp hlp) { + if(comm == null) throw new NullPointerException("Command must not be null"); - else if (commands.containsKey(c)) + else if(commands.containsKey(c)) throw new IllegalArgumentException(format("Character '%s' is already bound")); commands.put(c, comm); help.put(c, hlp); registered.add(c); - if (!changed) changed = true; + if(!changed) changed = true; } /** @@ -79,30 +101,33 @@ public class SimpleFDSMode implements FDSMode { * @param mode * The submode to add. * + * @param hlp + * The help for the submode. + * * @throws IllegalArgumentException * If the character is already bound to a submode. */ - public void addSubmode(char c, FDSMode mode, CommandHelp hlp) { - if (mode == null) + public void addSubmode(String c, FDSMode mode, CommandHelp hlp) { + if(mode == null) throw new NullPointerException("Mode must not be null"); - else if (modes.containsKey(c)) + else if(modes.containsKey(c)) throw new IllegalArgumentException(format("Character '%s' is already bound")); modes.put(c, mode); help.put(c, hlp); registered.add(c); - if (!changed) changed = true; + if(!changed) changed = true; } @Override - public char[] registeredChars() { - if (!changed) return registeredArray; + public String[] registeredChars() { + if(!changed) return registeredArray; - registeredArray = new char[registered.size()]; + registeredArray = new String[registered.size()]; int i = 0; - for (char c : registered) { + for(String c : registered) { registeredArray[i] = c; i += 1; @@ -114,18 +139,18 @@ public class SimpleFDSMode implements FDSMode { } @Override - public boolean hasCommand(char c) { + public boolean hasCommand(String c) { return commands.containsKey(c); } @Override - public boolean hasSubmode(char c) { + public boolean hasSubmode(String c) { return modes.containsKey(c); } @Override - public FDSCommand getCommand(char c) throws FDSException { - if (!commands.containsKey(c)) { + public FDSCommand getCommand(String c) throws FDSException { + if(!commands.containsKey(c)) { throw new FDSException(String.format("No command bound to '%s'", c)); } @@ -133,8 +158,8 @@ public class SimpleFDSMode implements FDSMode { } @Override - public FDSMode getSubmode(char c) throws FDSException { - if (!modes.containsKey(c)) { + public FDSMode getSubmode(String c) throws FDSException { + if(!modes.containsKey(c)) { throw new FDSException(String.format("No mode bound to '%s'", c)); } @@ -142,7 +167,7 @@ public class SimpleFDSMode implements FDSMode { } @Override - public Collection getHelp(char c) { + public Collection getHelp(String c) { return help.get(c); } } \ No newline at end of file -- cgit v1.2.3