Class DocumentPath

    • 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 path
        parentPath - the path representing the parent leading up to this node, in the case of the root this should be null
        Throws:
        IllegalDocumentNameException - if both parameters are null or name contains an illegal character ('.')
    • Method Detail

      • from

        public static DocumentPath from​(String path)
        Creates a new DocumentPath from a period delimited path string.
        Parameters:
        path - path string
        Returns:
        DocumentPath instance
      • from

        public static DocumentPath from​(String... elements)
        Creates a new DocumentPath from a list of path elements.
        Parameters:
        elements - path elements
        Returns:
        DocumentPath instance
      • from

        public static DocumentPath from​(List<String> elements)
        Creates a new DocumentPath 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 new DocumentPath from a list of path elements.
        Parameters:
        elements - path elements
        child - child element
        Returns:
        DocumentPath instance
      • from

        public static DocumentPath from​(List<String> elements,
                                        String... childElms)
        Creates a new DocumentPath from a list of path elements.
        Parameters:
        elements - path elements
        childElms - child element
        Returns:
        DocumentPath instance
      • append

        public DocumentPath append​(List<String> childElms)
        Creates a new DocumentPath element appending childElm 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 of r.a.b.c; while r.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 and root.a.b.c.d.e are descendants of r.a.b; while r.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
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object