Package org.onosproject.store.service
Class DocumentPath
- java.lang.Object
-
- org.onosproject.store.service.DocumentPath
-
- All Implemented Interfaces:
Comparable<DocumentPath>
public class DocumentPath extends Object implements Comparable<DocumentPath>
Unique key for nodes in theDocumentTree
.
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_SEPARATOR
Default path separator.static String
DEFAULT_SEPARATOR_RE
Default path separator regex.static DocumentPath
ROOT
Root document tree path.
-
Constructor Summary
Constructors Constructor Description DocumentPath(String nodeName, DocumentPath parentPath)
Constructs a new document path.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DocumentPath
append(List<String> childElms)
Creates a new DocumentPath element appendingchildElm
to this path.DocumentPath
childPath()
Returns the relative path to the given node.int
compareTo(DocumentPath that)
boolean
equals(Object obj)
static DocumentPath
from(String path)
Creates a newDocumentPath
from a period delimited path string.static DocumentPath
from(String... elements)
Creates a newDocumentPath
from a list of path elements.static DocumentPath
from(List<String> elements)
Creates a newDocumentPath
from a list of path elements.static DocumentPath
from(List<String> elements, String child)
Creates a newDocumentPath
from a list of path elements.static DocumentPath
from(List<String> elements, String... childElms)
Creates a newDocumentPath
from a list of path elements.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(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.List<String>
pathElements()
Returns the list of path elements representing this path in correct order.String
toString()
-
-
-
Field Detail
-
DEFAULT_SEPARATOR
public static final String DEFAULT_SEPARATOR
Default path separator.- See Also:
- Constant Field Values
-
DEFAULT_SEPARATOR_RE
public static final String DEFAULT_SEPARATOR_RE
Default path separator regex.- See Also:
- Constant Field Values
-
ROOT
public static final DocumentPath ROOT
Root document tree path.
-
-
Constructor Detail
-
DocumentPath
public DocumentPath(String nodeName, DocumentPath parentPath)
Constructs a new document path.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.- Parameters:
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 benull
- Throws:
IllegalDocumentNameException
- if both parameters are null or name contains an illegal character ('.')
-
-
Method Detail
-
from
public static DocumentPath from(String path)
Creates a newDocumentPath
from a period delimited path string.- Parameters:
path
- path string- Returns:
DocumentPath
instance
-
from
public static DocumentPath from(String... elements)
Creates a newDocumentPath
from a list of path elements.- Parameters:
elements
- path elements- Returns:
DocumentPath
instance
-
from
public static DocumentPath from(List<String> elements)
Creates a newDocumentPath
from a list of path elements.- Parameters:
elements
- path elements- Returns:
DocumentPath
instance
-
from
public static DocumentPath from(List<String> elements, String child)
Creates a newDocumentPath
from a list of path elements.- Parameters:
elements
- path elementschild
- child element- Returns:
DocumentPath
instance
-
from
public static DocumentPath from(List<String> elements, String... childElms)
Creates a newDocumentPath
from a list of path elements.- Parameters:
elements
- path elementschildElms
- child element- Returns:
DocumentPath
instance
-
append
public DocumentPath append(List<String> childElms)
Creates a new DocumentPath element appendingchildElm
to this path.- Parameters:
childElms
- to append- Returns:
- this + childElm
-
childPath
public DocumentPath childPath()
Returns the relative path to the given node.- Returns:
- relative path to the given node.
-
parent
public DocumentPath parent()
Returns a path for the parent of this node.- Returns:
- parent node path. If this path is for the root, returns
null
.
-
pathElements
public List<String> pathElements()
Returns the list of path elements representing this path in correct order.- Returns:
- a list of elements that make up this path
-
isAncestorOf
public boolean isAncestorOf(DocumentPath other)
Returns if the specified path belongs to a direct ancestor of the node pointed at by this path.Example:
root.a
is a direct ancestor ofr.a.b.c
; whiler.a.x
is not.- Parameters:
other
- other path- Returns:
true
is yes;false
otherwise.
-
isDescendentOf
public boolean isDescendentOf(DocumentPath other)
Returns if the specified path is belongs to a subtree rooted this path.Example:
root.a.b
androot.a.b.c.d.e
are descendants ofr.a.b
; whiler.a.x.c
is not.- Parameters:
other
- other path- Returns:
true
is yes;false
otherwise.
-
leastCommonAncestor
public static DocumentPath leastCommonAncestor(Collection<DocumentPath> paths)
Returns the path that points to the least common ancestor of the specified collection of paths.- Parameters:
paths
- collection of path- Returns:
- path to least common ancestor or null if there is nothing in common
-
compareTo
public int compareTo(DocumentPath that)
- Specified by:
compareTo
in interfaceComparable<DocumentPath>
-
-