+ static void buildTrie(String prefix, Hashtable cases) {
+ Enumeration caseKeys = cases.keys();
+ Vec keys = new Vec();
+ while(caseKeys.hasMoreElements()) keys.addElement(caseKeys.nextElement());
+ keys.sort(new Vec.CompareFunc() { public int compare(Object a, Object b) {
+ return ((String)a).compareTo((String)b);
+ } } );
+
+ for(int i=0; i<keys.size(); i++) {
+ String prefixPlusOne = ((String)keys.elementAt(i)).substring(0, prefix.length() + 1);
+ if (i<keys.size()-1 && prefixPlusOne.equals((((String)keys.elementAt(i + 1)).substring(0, prefix.length() + 1)))) {
+ System.out.println("case \'" + prefixPlusOne.charAt(prefixPlusOne.length() - 1) + "\': {");
+ System.out.println("switch(neverUseThis.charAt(" + prefix.length() + ")) {");
+ buildTrie(prefixPlusOne, cases);
+ System.out.println("} break; }");
+ while(i<keys.size()-1 &&
+ prefixPlusOne.equals(((String)keys.elementAt(i + 1)).substring(0, prefix.length() + 1))) {
+ i++;
+ prefixPlusOne = ((String)keys.elementAt(i)).substring(0, prefix.length() + 1);
+ }
+ i--;
+ } else {
+ String code = (String)cases.get(keys.elementAt(i));
+ code = code.substring(0, code.length() - 1);
+ String key = (String)keys.elementAt(i);
+ System.out.println("if (\""+key+"\".equals(neverUseThis)) { " + code + " } ");
+ }
+ }
+ }
+