Class Node

  • Direct Known Subclasses:
    TagNode, TextNode

    public abstract class Node
    extends Object
    Represents any element in the DOM tree of a HTML file.
    • Field Detail

    • Constructor Detail

      • Node

        public Node​(TagNode parent)
        This constructor not only sets the parameter as the parent for the created node, but also appends the created node to the collection of the parent's children.
        Parameters:
        parent - - the parent for the new node.
    • Method Detail

      • getParent

        public TagNode getParent()
        Returns:
        the parent itself (NOT a copy!)
      • getParentTree

        public List<TagNode> getParentTree()
        This method returns a list of the ancestors that is ordered starting from the root by the depth. Index of an element in that list corresponds its depth (if depth of the root is 0)
        Returns:
        ordered by depth list of the ancestors or an empty List<TagNode> if the parent is null.
      • getRoot

        public TagNode getRoot()
        "equals" method should work differently for the case where the compared nodes are from the same tree, and in that case return true only if it's the same object This method returns the root of the tree (which should be common ancestor for every node in the tree). If the roots are the same object, then the nodes are in the same tree.
        Returns:
        the "top" ancestor if this node has a parent,
        or
        the node itself if there is no parent, and this is a TagNode
        or
        null if there is no parents and this node isn't a TagNode
      • getMinimalDeletedSet

        public abstract List<Node> getMinimalDeletedSet​(long id)
      • detectIgnorableWhiteSpace

        public void detectIgnorableWhiteSpace()
      • getLastCommonParent

        public LastCommonParentResult getLastCommonParent​(Node other)
        Descent the ancestors list for both nodes stopping either at the first no-match case or when either of the lists is exhausted.
        Parameters:
        other - - the node to check for common parent
        Returns:
        result that contains last common parent, depth, index in the list of children of the common parent of an ancestor(or self) of this node that is immediate child of the common parent.
        Throws:
        IllegalArgumentException - if the parameter is null
      • setParent

        public void setParent​(TagNode parent)
        changes the parent field of this node. Does NOT append/remove itself from the previous or the new parent children collection.
        Parameters:
        parent - - new parent to assign
      • setRoot

        protected void setRoot​(TagNode root)
      • copyTree

        public abstract Node copyTree()
      • inPre

        public boolean inPre()
        Returns:
        true only if one of the ancestors is <pre> tag. false otherwise (including case where this node is <pre> tag)
      • isWhiteBefore

        public boolean isWhiteBefore()
      • setWhiteBefore

        public void setWhiteBefore​(boolean whiteBefore)
      • isWhiteAfter

        public boolean isWhiteAfter()
      • setWhiteAfter

        public void setWhiteAfter​(boolean whiteAfter)
      • getLeftMostChild

        public abstract Node getLeftMostChild()
      • getRightMostChild

        public abstract Node getRightMostChild()