summaryrefslogtreecommitdiff
path: root/base/src/examples/java
diff options
context:
space:
mode:
Diffstat (limited to 'base/src/examples/java')
-rw-r--r--base/src/examples/java/bjc/utils/examples/AbbrevMapTest.java46
1 files changed, 39 insertions, 7 deletions
diff --git a/base/src/examples/java/bjc/utils/examples/AbbrevMapTest.java b/base/src/examples/java/bjc/utils/examples/AbbrevMapTest.java
index ac4ea76..cd6e6f1 100644
--- a/base/src/examples/java/bjc/utils/examples/AbbrevMapTest.java
+++ b/base/src/examples/java/bjc/utils/examples/AbbrevMapTest.java
@@ -1,5 +1,7 @@
package bjc.utils.examples;
+import java.io.PrintStream;
+import java.util.List;
import java.util.Scanner;
import bjc.utils.esodata.AbbrevMap;
@@ -24,28 +26,39 @@ public class AbbrevMapTest {
final AbbrevMap map = new AbbrevMap();
System.out.print("Enter a command (blank line to quit): ");
- String ln = scn.nextLine();
+ String ln = scn.nextLine().trim();
while (!ln.equals("")) {
- final String[] commParts = ln.split(" ");
+ final List<String> commParts = StringUtils.processArguments(ln);
- switch (commParts[0]) {
+ switch (commParts.get(0)) {
case "add":
- map.addWords(commParts[1]);
+ map.addWords(commParts.get(1));
break;
case "remove":
- map.removeWords(commParts[1]);
+ map.removeWords(commParts.get(1));
break;
case "recalc":
map.recalculate();
break;
- case "check":
- final String list = StringUtils.toEnglishList(map.deabbrev(commParts[1]), false);
+ case "check": {
+ String[] strings = map.deabbrev(commParts.get(1));
+
+ final String list = StringUtils.toEnglishList(strings, false);
+
System.out.println(list);
break;
+ }
case "debug":
System.out.println(map.toString());
break;
+ case "help":
+ if(commParts.size() > 1) {
+ help(commParts.get(1));
+ } else {
+ help();
+ }
+ break;
default:
System.out.println("Unknown command: " + ln);
}
@@ -56,4 +69,23 @@ public class AbbrevMapTest {
scn.close();
}
+
+ private static void help() {
+ PrintStream strm = System.out;
+
+ strm.println("Abbreviation Map Testing Commands:");
+ strm.println("\tadd <word>\tAdd a word to the abbreviation map");
+ strm.println("\tremove <word>\tRemove a word from the abbreviation map");
+ strm.println("\trecalc \tRecalculate the abbreviation map");
+ strm.println("\tcheck <word>\tCheck all of the possible things a word could be an abbreviation for");
+ strm.println("\tdebug \tPrint out the abbreviation map");
+ strm.println("\thelp \tList commands, or get help on a command\n");
+ }
+
+ private static void help(String com) {
+ switch(com) {
+ default:
+ System.out.printf("\tNo help available for command: %s\n", com);
+ }
+ }
}