@Test public void test2 () { JsonValueVisitor[] vvs; String[] colExps; colExps = new String[] { "a", "b" }; vvs = new JsonValueVisitor[colExps.length]; TestRowEndListener listener = new TestRowEndListener (); JsonEventVisitor ev = JsonExpFactory.createVisitor ("", colExps, vvs, listener, false); for (int i = 0; i < vvs.length; ++i) { Assert.assertNotNull(vvs[i]); } TextJsonParser p = new TextJsonParser (new StringReader ("[{\"a\":123,\"b\":234},{\"a\":123,\"b\":234},{\"a\":1234,\"b\":2345}]")); int depth = 0; int rowCount = 0; while (p.hasNext ()) { JsonParser.Event e = p.next (); switch (e) { case START_OBJECT: case START_ARRAY: ev.visit (e, p, depth); ++depth; break; case END_OBJECT: case END_ARRAY: --depth; ev.visit (e, p, depth); break; default: ev.visit (e, p, depth); break; } if (listener.isRowEnd ()) { ++rowCount; listener.setRowEnd (false); } } Assert.assertEquals (3, rowCount); Assert.assertEquals ("1234", vvs[0].getValue ().toString ()); Assert.assertEquals ("2345", vvs[1].getValue ().toString ()); }
public static JsonEventVisitor createVisitor (String rowExp, String[] colExps, JsonValueVisitor[] valueVisitors, JsonRowEndListener listener, boolean rootAsArray) { String[] exps; if (rowExp == null || rowExp.length () == 0) exps = new String[0]; else exps = rowExp.split ("[.]"); JsonEventVisitor rootVisitor; JsonRowVisitor rv = new JsonRowVisitor (listener, rootAsArray); if (exps.length == 0) { rootVisitor = rv; } else { rootVisitor = createVisitors (null, exps, rv); } TreeMap<String, JsonValueVisitor> expMap = new TreeMap<String, JsonValueVisitor> (); JsonEventVisitor colRootVisitor = null; for (int i = 0; i < colExps.length; ++i) { String colExp = colExps[i]; JsonValueVisitor prevVV = expMap.get (colExp); if (prevVV != null) { valueVisitors[i] = prevVV; continue; } JsonValueVisitor vv = new JsonValueVisitor (); valueVisitors[i] = vv; expMap.put (colExp, vv); exps = colExp.split ("[.]"); colRootVisitor = createVisitors (colRootVisitor, exps, vv); } rv.setColVisitor (colRootVisitor); return rootVisitor; }
JsonExpFactory { public static JsonEventVisitor createVisitor (String rowExp, String[] colExps, JsonValueVisitor[] valueVisitors, JsonRowEndListener listener, boolean rootAsArray) { String[] exps; if (rowExp == null || rowExp.length () == 0) exps = new String[0]; else exps = rowExp.split ("[.]"); JsonEventVisitor rootVisitor; JsonRowVisitor rv = new JsonRowVisitor (listener, rootAsArray); if (exps.length == 0) { rootVisitor = rv; } else { rootVisitor = createVisitors (null, exps, rv); } TreeMap<String, JsonValueVisitor> expMap = new TreeMap<String, JsonValueVisitor> (); JsonEventVisitor colRootVisitor = null; for (int i = 0; i < colExps.length; ++i) { String colExp = colExps[i]; JsonValueVisitor prevVV = expMap.get (colExp); if (prevVV != null) { valueVisitors[i] = prevVV; continue; } JsonValueVisitor vv = new JsonValueVisitor (); valueVisitors[i] = vv; expMap.put (colExp, vv); exps = colExp.split ("[.]"); colRootVisitor = createVisitors (colRootVisitor, exps, vv); } rv.setColVisitor (colRootVisitor); return rootVisitor; } }
JsonExpFactory { public static JsonEventVisitor createVisitor (String rowExp, String[] colExps, JsonValueVisitor[] valueVisitors, JsonRowEndListener listener, boolean rootAsArray) { String[] exps; if (rowExp == null || rowExp.length () == 0) exps = new String[0]; else exps = rowExp.split ("[.]"); JsonEventVisitor rootVisitor; JsonRowVisitor rv = new JsonRowVisitor (listener, rootAsArray); if (exps.length == 0) { rootVisitor = rv; } else { rootVisitor = createVisitors (null, exps, rv); } TreeMap<String, JsonValueVisitor> expMap = new TreeMap<String, JsonValueVisitor> (); JsonEventVisitor colRootVisitor = null; for (int i = 0; i < colExps.length; ++i) { String colExp = colExps[i]; JsonValueVisitor prevVV = expMap.get (colExp); if (prevVV != null) { valueVisitors[i] = prevVV; continue; } JsonValueVisitor vv = new JsonValueVisitor (); valueVisitors[i] = vv; expMap.put (colExp, vv); exps = colExp.split ("[.]"); colRootVisitor = createVisitors (colRootVisitor, exps, vv); } rv.setColVisitor (colRootVisitor); return rootVisitor; }  }
JsonExpFactory { public static JsonEventVisitor createVisitor (String rowExp, String[] colExps, JsonValueVisitor[] valueVisitors, JsonRowEndListener listener, boolean rootAsArray) { String[] exps; if (rowExp == null || rowExp.length () == 0) exps = new String[0]; else exps = rowExp.split ("[.]"); JsonEventVisitor rootVisitor; JsonRowVisitor rv = new JsonRowVisitor (listener, rootAsArray); if (exps.length == 0) { rootVisitor = rv; } else { rootVisitor = createVisitors (null, exps, rv); } TreeMap<String, JsonValueVisitor> expMap = new TreeMap<String, JsonValueVisitor> (); JsonEventVisitor colRootVisitor = null; for (int i = 0; i < colExps.length; ++i) { String colExp = colExps[i]; JsonValueVisitor prevVV = expMap.get (colExp); if (prevVV != null) { valueVisitors[i] = prevVV; continue; } JsonValueVisitor vv = new JsonValueVisitor (); valueVisitors[i] = vv; expMap.put (colExp, vv); exps = colExp.split ("[.]"); colRootVisitor = createVisitors (colRootVisitor, exps, vv); } rv.setColVisitor (colRootVisitor); return rootVisitor; }  static JsonEventVisitor createVisitor(String rowExp, String[] colExps, JsonValueVisitor[] valueVisitors, JsonRowEndListener listener, boolean rootAsArray); }
JsonExpFactory { public static JsonEventVisitor createVisitor (String rowExp, String[] colExps, JsonValueVisitor[] valueVisitors, JsonRowEndListener listener, boolean rootAsArray) { String[] exps; if (rowExp == null || rowExp.length () == 0) exps = new String[0]; else exps = rowExp.split ("[.]"); JsonEventVisitor rootVisitor; JsonRowVisitor rv = new JsonRowVisitor (listener, rootAsArray); if (exps.length == 0) { rootVisitor = rv; } else { rootVisitor = createVisitors (null, exps, rv); } TreeMap<String, JsonValueVisitor> expMap = new TreeMap<String, JsonValueVisitor> (); JsonEventVisitor colRootVisitor = null; for (int i = 0; i < colExps.length; ++i) { String colExp = colExps[i]; JsonValueVisitor prevVV = expMap.get (colExp); if (prevVV != null) { valueVisitors[i] = prevVV; continue; } JsonValueVisitor vv = new JsonValueVisitor (); valueVisitors[i] = vv; expMap.put (colExp, vv); exps = colExp.split ("[.]"); colRootVisitor = createVisitors (colRootVisitor, exps, vv); } rv.setColVisitor (colRootVisitor); return rootVisitor; }  static JsonEventVisitor createVisitor(String rowExp, String[] colExps, JsonValueVisitor[] valueVisitors, JsonRowEndListener listener, boolean rootAsArray);  }