Class DocumentPath

  • All Implemented Interfaces:
    java.lang.Comparable<DocumentPath>

    public class DocumentPath
    extends java.lang.Object
    implements java.lang.Comparable<DocumentPath>
    Unique key for nodes in the DocumentTree.
    • Constructor Summary

      Constructors 
      Constructor Description
      DocumentPath​(java.lang.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​(java.util.List<java.lang.String> childElms)
      Creates a new DocumentPath element appending childElm to this path.
      DocumentPath childPath()
      Returns the relative path to the given node.
      int compareTo​(DocumentPath that)  
      boolean equals​(java.lang.Object obj)  
      static DocumentPath from​(java.lang.String path)
      Creates a new DocumentPath from a period delimited path string.
      static DocumentPath from​(java.lang.String... elements)
      Creates a new DocumentPath from a list of path elements.
      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.util.List<java.lang.String> elements, java.lang.String... childElms)
      Creates a new DocumentPath 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​(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()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • DEFAULT_SEPARATOR

        public static final java.lang.String DEFAULT_SEPARATOR
        Default path separator.
        See Also:
        Constant Field Values
      • DEFAULT_SEPARATOR_RE

        public static final java.lang.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​(java.lang.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​(java.lang.String path)
        Creates a new DocumentPath from a period delimited path string.
        Parameters:
        path - path string
        Returns:
        DocumentPath instance
      • from

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

        public static DocumentPath from​(java.util.List<java.lang.String> elements)
        Creates a new DocumentPath from a list of path elements.
        Parameters:
        elements - path elements
        Returns:
        DocumentPath instance
      • from

        public static DocumentPath from​(java.util.List<java.lang.String> elements,
                                        java.lang.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​(java.util.List<java.lang.String> elements,
                                        java.lang.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​(java.util.List<java.lang.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 java.util.List<java.lang.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​(java.util.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 java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • compareTo

        public int compareTo​(DocumentPath that)
        Specified by:
        compareTo in interface java.lang.Comparable<DocumentPath>