@Override public Path append(Path relPath) { if (relPath.isRoot()) return this; if (relPath.isSingle()) return new ChildPath(this, relPath.lastSegment().get()); String[] segments = new String[size() + relPath.size()]; int offset = this.copyInto(segments, 0); copyPathInto(relPath, segments, offset); return new MultiSegmentPath(segments); }
/** * Create a new path consisting of this path appended with the given path that will be treated as a relative path. * @param relPath the relative path to be appended to this path; may not be null * @return the new path */ Path append(Path relPath);
/** * Call the consumer with the path of every ancestor (except root) down to this path. * * @param consumer the function to call on each path segment */ default void fromRoot(Consumer<Path> consumer) { Path path = root(); for (String segment : this) { path = path.append(segment); consumer.accept(path); } } }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj instanceof Path) { Path that = (Path) obj; if (this.size() != that.size()) return false; if (!this.parent.equals(that.parent())) return false; return this.segment.equals(that.lastSegment().get()); } return false; }
@Test public void shouldParseMultiAbsolutePath() { path = parse("/a/b/c/d/e"); assertThat(path.isRoot()).isFalse(); assertThat(path.isSingle()).isFalse(); assertThat(path.size()).isEqualTo(5); assertThat(path.segment(0)).isEqualTo("a"); assertThat(path.segment(1)).isEqualTo("b"); assertThat(path.segment(2)).isEqualTo("c"); assertThat(path.segment(3)).isEqualTo("d"); assertThat(path.segment(4)).isEqualTo("e"); }
if (path.isRoot()) { if (path.isSingle()) { set(path.lastSegment().get(), value); return Optional.ofNullable(value); Path parentPath = path.parent().get(); Optional<Value> parent = Optional.empty(); if (!addIntermediaries) { String nextSegment = path.segment(missingIndex + 1); // can always find next segment 'path' (not 'parentPath')... if (Path.Segments.isArrayIndex(nextSegment)) { return Optional.of(Value.create(Array.create())); String lastSegment = path.lastSegment().get(); Value parentValue = parent.get(); if (parentValue.isDocument()) {
/** * Return whether this path has a single segment. This method is equivalent to {@code size() == 1}. * * @return true if this path contains exactly one segment, or false otherwise */ default boolean isSingle() { return size() == 1; }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj instanceof Path) { Path that = (Path) obj; if (this.size() != that.size()) return false; return this.lastSegment().get().equals(that.lastSegment().get()); } return false; }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj instanceof Path) { Path that = (Path) obj; if (this.size() != that.size()) return false; Iterator<String> thisIter = this.iterator(); Iterator<String> thatIter = that.iterator(); while (thisIter.hasNext()) { if (!thisIter.next().equals(thatIter.next())) return false; } return true; } return false; }
protected void assertPair( Iterator<Map.Entry<Path, Value>> iterator, String path, Object value ) { Map.Entry<Path,Value> entry = iterator.next(); assertThat((Object)entry.getKey()).isEqualTo(Path.parse(path)); assertThat(entry.getValue()).isEqualTo(Value.create(value)); }
@Override public Optional<Path> parent() { return Path.optionalRoot(); }
if (path.isRoot()) { if (path.isSingle()) { set(path.lastSegment().get(), value); return Optional.ofNullable(value); Path parentPath = path.parent().get(); Optional<Value> parent = Optional.empty(); if (!addIntermediaries) { String nextSegment = path.segment(missingIndex + 1); // can always find next segment 'path' (not 'parentPath')... if (Path.Segments.isArrayIndex(nextSegment)) { return Optional.of(Value.create(Array.create())); String lastSegment = path.lastSegment().get(); Value parentValue = parent.get(); if (parentValue.isDocument()) {
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj instanceof Path) { Path that = (Path) obj; if (this.size() != that.size()) return false; if (!this.parent.equals(that.parent())) return false; return this.segment.equals(that.lastSegment().get()); } return false; }
/** * Return whether this path has more than one segment. This method is equivalent to {@code size() > 1}. * * @return true if this path contains exactly one segment, or false otherwise */ default boolean isMultiple() { return size() > 1; }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj instanceof Path) { Path that = (Path) obj; if (this.size() != that.size()) return false; return this.lastSegment().get().equals(that.lastSegment().get()); } return false; }