Class ContainerNode

java.lang.Object
eu.maveniverse.domtrip.Node
eu.maveniverse.domtrip.ContainerNode
Direct Known Subclasses:
Document, Element

public abstract class ContainerNode extends Node
Abstract base class for Document and Element nodes that can contain child nodes.
  • Field Details

    • children

      protected List<Node> children
  • Constructor Details

    • ContainerNode

      protected ContainerNode()
  • Method Details

    • children

      public Stream<Node> children()
      Returns a Stream of child nodes.
      Returns:
      a Stream of child nodes
    • addChild

      public void addChild(Node node)
      Adds the given node as a child to this ContainerNode.
      Parameters:
      node - the Node to add
      Throws:
      IllegalArgumentException - if node is null
    • insertChild

      public void insertChild(int index, Node node)
      Inserts a child Node at the specified index.
      Parameters:
      index - a zero based index at which to insert the specified Node
      node - the node to insert
      Throws:
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index > nodeCount())
      IllegalArgumentException - if node is null
    • insertChildBefore

      public void insertChildBefore(Node referenceNode, Node newNode)
      Inserts a child Node before the specified referenceNode, if referenceNode is not null; otherwise behaves the same as addChild(newNode).
      Parameters:
      referenceNode - the node before which the newNode should be inserted
      newNode - the Node to insert
      Throws:
      IllegalArgumentException - if newNode is or when referenceNode is not a child of this ContainerNode
      Since:
      0.6.0
    • insertChildAfter

      public void insertChildAfter(Node referenceNode, Node newNode)
      Inserts a child Node after the specified referenceNode, if referenceNode is not null; otherwise behaves the same as addChild(newNode).
      Parameters:
      referenceNode - the node after which the newNode should be inserted
      newNode - the Node to insert
      Throws:
      IllegalArgumentException - if newNode is or when referenceNode is not a child of this ContainerNode
      Since:
      0.6.0
    • replaceChild

      public void replaceChild(Node existingNode, Node replacementNode)
      Replace the existingNode Node with the given replacementNode, if existingNode is not null; otherwise behaves the same as addChild(replacementNode).
      Parameters:
      existingNode - the Node to replace
      replacementNode - the Node to put in place of existingNode
      Throws:
      IllegalArgumentException - if replacementNode is null or when existingNode is not a child of this ContainerNode
      Since:
      0.6.0
    • removeChild

      public boolean removeChild(Node node)
      Removes the given child Node from this ContainerNode.
      Parameters:
      node - the Node to remove
      Returns:
      true if this ContainerNode contained the specified Node and false otherwise
    • child

      public Node child(int index)
      Gets the child at the specified index.
      Parameters:
      index - a zero based index of the child Node to return
      Returns:
      the child node at the specified index
      Throws:
      IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= nodeCount())
    • firstChild

      public Optional<Node> firstChild()
      Gets the first child.
      Returns:
      an Optional holding the last first if this ContainerNode has any children or otherwise and empty Optional
      Since:
      0.6.0
    • lastChild

      public Optional<Node> lastChild()
      Gets the last child.
      Returns:
      an Optional holding the last child if this ContainerNode has any children or otherwise and empty Optional
      Since:
      0.6.0
    • getNode

      @Deprecated public Node getNode(int index)
      Deprecated.
      Use child(int) instead.
      Gets the child node at the specified index.
      Parameters:
      index - the index of the child node
      Returns:
      the child node at the specified index
    • childCount

      public int childCount()
      Returns:
      the number of child nodes
    • findTextNode

      public Optional<Text> findTextNode()
      Returns:
      and Optional holding the first text node child or an empty Optional if there is no text child under this ContainerNode
    • textContent

      public String textContent()
      Returns:
      the text content of this node (concatenates all text children).
    • hasChildElements

      public boolean hasChildElements()
      Returns:
      true if this ContainerNode has any child Elements or false otherwise
    • hasTextContent

      public boolean hasTextContent()
      Returns:
      true if this ContainerNode has any child Text nodes or false otherwise
    • isEmpty

      public boolean isEmpty()
      Returns:
      true if this ContainerNode has no child nodes or false otherwise
    • clearChildren

      public void clearChildren()
      Removes all child nodes from this ContainerNode.
    • clearModified

      public void clearModified()
      Overrides:
      clearModified in class Node