Package io.debezium.document
Interface Path
-
- All Known Implementing Classes:
Paths.ChildPath,Paths.MultiSegmentPath,Paths.RootPath,Paths.SingleSegmentPath
@Immutable public interface Path extends Iterable<String>
A representation of multiple name segments that together form a path withinDocument.- Author:
- Randall Hauch
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfacePath.Segments
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Pathappend(Path relPath)Create a new path consisting of this path appended with the given path that will be treated as a relative path.default Pathappend(String relPath)Create a new path consisting of this path with one or more additional segments given by the relative path.default voidfromRoot(Consumer<Path> consumer)Call the consumer with the path of every ancestor (except root) down to this path.default booleanisMultiple()Return whether this path has more than one segment.default booleanisRoot()Return whether this path is the root path with no segments.default booleanisSingle()Return whether this path has a single segment.Optional<String>lastSegment()Get the last segment, if there is one.static Optional<Path>optionalRoot()Get anOptionalreference to the root path.Optional<Path>parent()Get the optional parent path.static Pathparse(String path)Parse a JSON Path expression.static Pathparse(String path, boolean resolveJsonPointerEscapes)Parse a JSON Path expression.static Pathroot()Get the zero-length path.Stringsegment(int index)Get the segment at the given index.intsize()Get the number of segments in the path.Pathsubpath(int length)Get a portion of this path that has a specified number of segments.StringtoRelativePath()Obtain the representation of this path as a relative path without the leading '/'.-
Methods inherited from interface java.lang.Iterable
forEach, iterator, spliterator
-
-
-
-
Method Detail
-
root
static Path root()
Get the zero-length path.- Returns:
- the shared root path; never null
-
optionalRoot
static Optional<Path> optionalRoot()
Get anOptionalreference to the root path. The resulting Optional will alwaysbe present.- Returns:
- the shared optional root path; never null
-
parse
static Path parse(String path)
Parse a JSON Path expression. Segments are separated by a single forward slash ('/'); any '~' or '/' literals must be escaped. Trailing slashes are ignored.- Parameters:
path- the path as a string; may not be null, but may be an empty string or "/" for a root path- Returns:
- the path object; never null
-
parse
static Path parse(String path, boolean resolveJsonPointerEscapes)
Parse a JSON Path expression. Segments are separated by a single forward slash ('/'); any '~' or '/' literals must be escaped. Trailing slashes are ignored.- Parameters:
path- the path as a string; may not be null, but may be an empty string or "/" for a root pathresolveJsonPointerEscapes-trueif '~' and '/' literals are to be escaped as '~0' and '~1', respectively, orfalseif they are not to be escaped- Returns:
- the path object; never null
-
isRoot
default boolean isRoot()
Return whether this path is the root path with no segments. This method is equivalent tosize() == 0.- Returns:
- true if this path contains exactly one segment, or false otherwise
-
isSingle
default boolean isSingle()
Return whether this path has a single segment. This method is equivalent tosize() == 1.- Returns:
- true if this path contains exactly one segment, or false otherwise
-
isMultiple
default boolean isMultiple()
Return whether this path has more than one segment. This method is equivalent tosize() > 1.- Returns:
- true if this path contains exactly one segment, or false otherwise
-
size
int size()
Get the number of segments in the path.- Returns:
- the size of the path; never negative
-
parent
Optional<Path> parent()
Get the optional parent path.- Returns:
- an optional containing the parent (if this is not the root path), or an empty optional if this is the root path.
-
lastSegment
Optional<String> lastSegment()
Get the last segment, if there is one.- Returns:
- an optional containing the last segment of this path (if this is not the root path), or an empty optional if this is the root path.
-
subpath
Path subpath(int length)
Get a portion of this path that has a specified number of segments.- Parameters:
length- the number of segments- Returns:
- the subpath, or this path if the supplied length is equal to
this.size()
-
segment
String segment(int index)
Get the segment at the given index.- Parameters:
index- the index of the segment- Returns:
- the segment
- Throws:
IllegalArgumentException- if the index value is equal to or greater than #size()
-
append
default Path append(String relPath)
Create a new path consisting of this path with one or more additional segments given by the relative path.- Parameters:
relPath- the relative path to be appended to this path; may not be null- Returns:
- the new path
-
append
Path append(Path relPath)
Create a new path consisting of this path appended with the given path that will be treated as a relative path.- Parameters:
relPath- the relative path to be appended to this path; may not be null- Returns:
- the new path
-
toRelativePath
String toRelativePath()
Obtain the representation of this path as a relative path without the leading '/'.- Returns:
- the relative path; never null but may be empty
-
-