public class DocumentPath extends java.lang.Object implements java.lang.Comparable<DocumentPath>
DocumentTree
.Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_SEPARATOR
Default path separator.
|
static java.lang.String |
DEFAULT_SEPARATOR_RE
Default path separator regex.
|
static DocumentPath |
ROOT
Root document tree path.
|
Constructor and Description |
---|
DocumentPath(java.lang.String nodeName,
DocumentPath parentPath)
Constructs a new document path.
|
Modifier and Type | Method and Description |
---|---|
DocumentPath |
childPath()
Returns the relative path to the given node.
|
int |
compareTo(DocumentPath that) |
boolean |
equals(java.lang.Object obj) |
static DocumentPath |
from(java.util.List<java.lang.String> elements)
Creates a new
DocumentPath from a list of path elements. |
static DocumentPath |
from(java.util.List<java.lang.String> elements,
java.lang.String child)
Creates a new
DocumentPath from a list of path elements. |
static DocumentPath |
from(java.lang.String... elements)
Creates a new
DocumentPath from a list of path elements. |
static DocumentPath |
from(java.lang.String path)
Creates a new
DocumentPath from a period delimited path string. |
int |
hashCode() |
boolean |
isAncestorOf(DocumentPath other)
Returns if the specified path belongs to a direct ancestor of the node pointed at by this path.
|
boolean |
isDescendentOf(DocumentPath other)
Returns if the specified path is belongs to a subtree rooted this path.
|
static DocumentPath |
leastCommonAncestor(java.util.Collection<DocumentPath> paths)
Returns the path that points to the least common ancestor of the specified
collection of paths.
|
DocumentPath |
parent()
Returns a path for the parent of this node.
|
java.util.List<java.lang.String> |
pathElements()
Returns the list of path elements representing this path in correct
order.
|
java.lang.String |
toString() |
public static final java.lang.String DEFAULT_SEPARATOR
public static final java.lang.String DEFAULT_SEPARATOR_RE
public static final DocumentPath ROOT
public DocumentPath(java.lang.String nodeName, DocumentPath parentPath)
New paths must contain at least one name and string names MUST NOT contain
any path separator characters.
If one field is null
that field will be ignored.
nodeName
- the name of the last level of this pathparentPath
- the path representing the parent leading up to this
node, in the case of the root this should be null
IllegalDocumentNameException
- if both parameters are null or name contains an illegal character ('.')public static DocumentPath from(java.lang.String path)
DocumentPath
from a period delimited path string.path
- path stringDocumentPath
instancepublic static DocumentPath from(java.lang.String... elements)
DocumentPath
from a list of path elements.elements
- path elementsDocumentPath
instancepublic static DocumentPath from(java.util.List<java.lang.String> elements)
DocumentPath
from a list of path elements.elements
- path elementsDocumentPath
instancepublic static DocumentPath from(java.util.List<java.lang.String> elements, java.lang.String child)
DocumentPath
from a list of path elements.elements
- path elementschild
- child elementDocumentPath
instancepublic DocumentPath childPath()
public DocumentPath parent()
null
.public java.util.List<java.lang.String> pathElements()
public boolean isAncestorOf(DocumentPath other)
Example: root.a
is a direct ancestor of r.a.b.c
; while r.a.x
is not.
other
- other pathtrue
is yes; false
otherwise.public boolean isDescendentOf(DocumentPath other)
Example: root.a.b
and root.a.b.c.d.e
are descendants of r.a.b
;
while r.a.x.c
is not.
other
- other pathtrue
is yes; false
otherwise.public static DocumentPath leastCommonAncestor(java.util.Collection<DocumentPath> paths)
paths
- collection of pathpublic int hashCode()
hashCode
in class java.lang.Object
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public int compareTo(DocumentPath that)
compareTo
in interface java.lang.Comparable<DocumentPath>