< prev index next >

test/java/text/Format/common/PParser.java

Print this page

        

*** 56,66 **** protected int column; public PParser() { } ! public Hashtable parse(Reader r) throws IOException { this.reader = r; bufferedToken = false; lineNumber = 0; column = 0; if (getToken() != OPEN_PAIR) { --- 56,66 ---- protected int column; public PParser() { } ! public Map<String,Object> parse(Reader r) throws IOException { this.reader = r; bufferedToken = false; lineNumber = 0; column = 0; if (getToken() != OPEN_PAIR) {
*** 89,114 **** } return null; } protected Object parseArray() throws IOException { ! Vector array = new Vector(); int token; while ((token = getToken()) != CLOSE_ARRAY) { if (token == MORE) { token = getToken(); } if (token != CLOSE_ARRAY) { ! array.addElement(parseValue(token)); } } return array; } ! protected Hashtable parsePair() throws IOException { ! Hashtable ht = new Hashtable(11); int token; while ((token = getToken()) != CLOSE_PAIR) { if (token != STRING) { error("Pair expecting string got"); --- 89,114 ---- } return null; } protected Object parseArray() throws IOException { ! List<Object> array = new ArrayList<>(); int token; while ((token = getToken()) != CLOSE_ARRAY) { if (token == MORE) { token = getToken(); } if (token != CLOSE_ARRAY) { ! array.add(parseValue(token)); } } return array; } ! protected Map<String,Object> parsePair() throws IOException { ! Map<String,Object> ht = new HashMap<>(11); int token; while ((token = getToken()) != CLOSE_PAIR) { if (token != STRING) { error("Pair expecting string got");
*** 136,145 **** --- 136,146 ---- int token = getToken(false, false); return token; } + @SuppressWarnings("fallthrough") protected int getToken(boolean wantsWS, boolean inString) throws IOException { if (bufferedToken) { bufferedToken = false; if (lastToken != WS || wantsWS) {
*** 223,257 **** protected void error(String errorString) { throw new RuntimeException(errorString + " at line " + lineNumber + " column " + column); } public static void dump(Object o) { if (o instanceof String) { System.out.print(o); ! } else if(o instanceof Vector) { ! Enumeration e = ((Vector)o).elements(); ! dump(" ("); ! while (e.hasMoreElements()) { ! dump(e.nextElement()); dump(" -- "); ! } dump(" )"); } else { ! Hashtable ht = (Hashtable)o; ! Enumeration e = ht.keys(); ! dump(" {"); ! while (e.hasMoreElements()) { ! Object key = e.nextElement(); ! ! dump(key); dump(" = "); ! dump(ht.get(key)); dump(";"); ! } dump(" }"); } } public static void main(String[] args) { --- 224,253 ---- protected void error(String errorString) { throw new RuntimeException(errorString + " at line " + lineNumber + " column " + column); } + @SuppressWarnings("unchecked") public static void dump(Object o) { if (o instanceof String) { System.out.print(o); ! } else if(o instanceof List) { dump(" ("); ! ((List)o).forEach((l) -> { ! dump(l); dump(" -- "); ! }); dump(" )"); } else { ! Map<String,Object> ht = (Map<String,Object>)o; dump(" {"); ! ht.keySet().forEach(l -> { ! dump(l); dump(" = "); ! dump(ht.get(l)); dump(";"); ! }); dump(" }"); } } public static void main(String[] args) {
*** 259,269 **** System.out.println("need filename"); } else { try { FileReader fr = new FileReader(args[0]); PParser parser = new PParser(); ! Hashtable ht = parser.parse(fr); dump(ht); System.out.println(); } catch (IOException ioe) { --- 255,265 ---- System.out.println("need filename"); } else { try { FileReader fr = new FileReader(args[0]); PParser parser = new PParser(); ! Map<String,Object> ht = parser.parse(fr); dump(ht); System.out.println(); } catch (IOException ioe) {
< prev index next >