/** * Constructs a pruner by parsing a textual specification. * This lists the properties which should be included at each level of the hierarchy. * Properties are separated by commas and nested objects are inside square braces. * For example, {@code a,b[c,d]} will emit the top-level property {@code a} but * none of its children, and the top-level property {@code b} and only those * of its children named {@code c} and {@code d}. * @param spec textual specification of tree * @throws IllegalArgumentException if the syntax is incorrect */ public NamedPathPruner(String spec) throws IllegalArgumentException { this(parse(spec)); }
/** * Constructs a pruner by parsing a textual specification. * This lists the properties which should be included at each level of the hierarchy. * Properties are separated by commas and nested objects are inside square braces. * For example, {@code a,b[c,d]} will emit the top-level property {@code a} but * none of its children, and the top-level property {@code b} and only those * of its children named {@code c} and {@code d}. * @param spec textual specification of tree * @throws IllegalArgumentException if the syntax is incorrect */ public NamedPathPruner(String spec) throws IllegalArgumentException { this(parse(spec)); }
/** * Constructs a pruner by parsing a textual specification. * This lists the properties which should be included at each level of the hierarchy. * Properties are separated by commas and nested objects are inside square braces. * For example, {@code a,b[c,d]} will emit the top-level property {@code a} but * none of its children, and the top-level property {@code b} and only those * of its children named {@code c} and {@code d}. * @param spec textual specification of tree * @throws IllegalArgumentException if the syntax is incorrect */ public NamedPathPruner(String spec) throws IllegalArgumentException { this(parse(spec)); }
private static void assertParseError(String spec) { try { NamedPathPruner.parse(spec); fail(); } catch (IllegalArgumentException x) { // pass } }
public void testParse() throws Exception { assertEquals("{a={}, b={c={}}}", NamedPathPruner.parse("a,b[c]").toString()); assertEquals("{a={}, b={c={}, d={}}}", NamedPathPruner.parse("a,b[c,d]").toString()); assertEquals("{a={}, b={c={}, d={}}, e={}}", NamedPathPruner.parse("a,b[c,d],e").toString()); assertEquals("{a={}, b={c={}, d={}}, e={}}", NamedPathPruner.parse("a,b[c,d]{,10},e").toString()); assertParseError(""); assertParseError("a,"); assertParseError(",b"); assertParseError("a["); assertParseError("a[b,c"); assertParseError("a[]"); assertParseError("a[b,,]"); assertParseError("a]"); assertParseError("a{}"); assertParseError("a{b}"); } private static void assertParseError(String spec) {