@Test(expected = ParsingException.class) public void oneSingleCharsElement() { Path path = KeyPathParser.parse("$[\"\"]"); assertThat(path.elements().size(), is(2)); assertThat(path.elements().get(0).isRoot(), is(true)); assertThat(path.elements().get(0).id(), is("$")); assertThat(path.elements().get(1).isRoot(), is(false)); assertThat(path.elements().get(1).id(), is("")); }
public static Path parse(String path) { path = path == null ? "" : path.trim(); if (path.length() < 1) { throw new IllegalArgumentException("Empty or null input"); } List<Element> elements = new ArrayList<>(); StringBuilder value = new StringBuilder(); State state = State.START; char[] chars = path.toCharArray(); int i; for (i = 0; i < chars.length; i++) { state = state.next(chars[i], i, elements, value); } state = state.next((char) 0, i, elements, value); if (state != State.EOF) { throw new ParsingException("Unexpected end of file"); } return new Path(Collections.unmodifiableList(elements)); }
KeyPathParser { public static Path parse(String path) { path = path == null ? "" : path.trim(); if (path.length() < 1) { throw new IllegalArgumentException("Empty or null input"); } List<Element> elements = new ArrayList<>(); StringBuilder value = new StringBuilder(); State state = State.START; char[] chars = path.toCharArray(); int i; for (i = 0; i < chars.length; i++) { state = state.next(chars[i], i, elements, value); } state = state.next((char) 0, i, elements, value); if (state != State.EOF) { throw new ParsingException("Unexpected end of file"); } return new Path(Collections.unmodifiableList(elements)); } }
KeyPathParser { public static Path parse(String path) { path = path == null ? "" : path.trim(); if (path.length() < 1) { throw new IllegalArgumentException("Empty or null input"); } List<Element> elements = new ArrayList<>(); StringBuilder value = new StringBuilder(); State state = State.START; char[] chars = path.toCharArray(); int i; for (i = 0; i < chars.length; i++) { state = state.next(chars[i], i, elements, value); } state = state.next((char) 0, i, elements, value); if (state != State.EOF) { throw new ParsingException("Unexpected end of file"); } return new Path(Collections.unmodifiableList(elements)); }  }
KeyPathParser { public static Path parse(String path) { path = path == null ? "" : path.trim(); if (path.length() < 1) { throw new IllegalArgumentException("Empty or null input"); } List<Element> elements = new ArrayList<>(); StringBuilder value = new StringBuilder(); State state = State.START; char[] chars = path.toCharArray(); int i; for (i = 0; i < chars.length; i++) { state = state.next(chars[i], i, elements, value); } state = state.next((char) 0, i, elements, value); if (state != State.EOF) { throw new ParsingException("Unexpected end of file"); } return new Path(Collections.unmodifiableList(elements)); }  static Path parse(String path); }
KeyPathParser { public static Path parse(String path) { path = path == null ? "" : path.trim(); if (path.length() < 1) { throw new IllegalArgumentException("Empty or null input"); } List<Element> elements = new ArrayList<>(); StringBuilder value = new StringBuilder(); State state = State.START; char[] chars = path.toCharArray(); int i; for (i = 0; i < chars.length; i++) { state = state.next(chars[i], i, elements, value); } state = state.next((char) 0, i, elements, value); if (state != State.EOF) { throw new ParsingException("Unexpected end of file"); } return new Path(Collections.unmodifiableList(elements)); }  static Path parse(String path);  }