Package eu.maveniverse.domtrip
Class ContainerNode
- java.lang.Object
-
- eu.maveniverse.domtrip.Node
-
- eu.maveniverse.domtrip.ContainerNode
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class eu.maveniverse.domtrip.Node
Node.NodeType
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedContainerNode()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddChild(Node node)Adds the givennodeas a child to thisContainerNode.Nodechild(int index)Gets the child at the specified index.intchildCount()java.util.stream.Stream<Node>children()Returns aStreamof child nodes.voidclearChildren()Removes all child nodes from thisContainerNode.voidclearModified()java.util.Optional<Text>findTextNode()java.util.Optional<Node>firstChild()Gets the first child.NodegetNode(int index)Deprecated.Usechild(int)instead.booleanhasChildElements()booleanhasTextContent()voidinsertChild(int index, Node node)Inserts a childNodeat the specified index.voidinsertChildAfter(Node referenceNode, Node newNode)Inserts a childNodeafter the specifiedreferenceNode, ifreferenceNodeis notnull; otherwise behaves the same asaddChild(newNode).voidinsertChildBefore(Node referenceNode, Node newNode)Inserts a childNodebefore the specifiedreferenceNode, ifreferenceNodeis notnull; otherwise behaves the same asaddChild(newNode).booleanisEmpty()java.util.Optional<Node>lastChild()Gets the last child.booleanremoveChild(Node node)Removes the given childNodefrom thisContainerNode.voidreplaceChild(Node existingNode, Node replacementNode)Replace theexistingNodeNodewith the givenreplacementNode, ifexistingNodeis notnull; otherwise behaves the same asaddChild(replacementNode).java.lang.StringtextContent()-
Methods inherited from class eu.maveniverse.domtrip.Node
accept, clone, copy, depth, document, isDescendantOf, isModified, markModified, nextSibling, nextSiblingElement, parent, parent, parentElement, precedingWhitespace, precedingWhitespace, previousSibling, previousSiblingElement, siblingIndex, toXml, toXml, type
-
-
-
-
Field Detail
-
children
protected java.util.List<Node> children
-
-
Method Detail
-
children
public java.util.stream.Stream<Node> children()
Returns aStreamof child nodes.- Returns:
- a
Streamof child nodes
-
addChild
public void addChild(Node node)
Adds the givennodeas a child to thisContainerNode.- Parameters:
node- theNodeto add- Throws:
java.lang.IllegalArgumentException- ifnodeisnull
-
insertChild
public void insertChild(int index, Node node)Inserts a childNodeat the specified index.- Parameters:
index- a zero based index at which to insert the specifiedNodenode- the node to insert- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index > nodeCount())java.lang.IllegalArgumentException- if node is null
-
insertChildBefore
public void insertChildBefore(Node referenceNode, Node newNode)
Inserts a childNodebefore the specifiedreferenceNode, ifreferenceNodeis notnull; otherwise behaves the same asaddChild(newNode).- Parameters:
referenceNode- the node before which thenewNodeshould be insertednewNode- theNodeto insert- Throws:
java.lang.IllegalArgumentException- ifnewNodeis or whenreferenceNodeis not a child of thisContainerNode- Since:
- 0.6.0
-
insertChildAfter
public void insertChildAfter(Node referenceNode, Node newNode)
Inserts a childNodeafter the specifiedreferenceNode, ifreferenceNodeis notnull; otherwise behaves the same asaddChild(newNode).- Parameters:
referenceNode- the node after which thenewNodeshould be insertednewNode- theNodeto insert- Throws:
java.lang.IllegalArgumentException- ifnewNodeis or whenreferenceNodeis not a child of thisContainerNode- Since:
- 0.6.0
-
replaceChild
public void replaceChild(Node existingNode, Node replacementNode)
Replace theexistingNodeNodewith the givenreplacementNode, ifexistingNodeis notnull; otherwise behaves the same asaddChild(replacementNode).- Parameters:
existingNode- theNodeto replacereplacementNode- theNodeto put in place ofexistingNode- Throws:
java.lang.IllegalArgumentException- ifreplacementNodeisnullor whenexistingNodeis not a child of thisContainerNode- Since:
- 0.6.0
-
removeChild
public boolean removeChild(Node node)
Removes the given childNodefrom thisContainerNode.- Parameters:
node- theNodeto remove- Returns:
trueif thisContainerNodecontained the specifiedNodeandfalseotherwise
-
child
public Node child(int index)
Gets the child at the specified index.- Parameters:
index- a zero based index of the childNodeto return- Returns:
- the child node at the specified index
- Throws:
java.lang.IndexOutOfBoundsException- if the index is out of range (index < 0 || index >= nodeCount())
-
firstChild
public java.util.Optional<Node> firstChild()
Gets the first child.- Returns:
- an
Optionalholding the last first if thisContainerNodehas any children or otherwise and emptyOptional - Since:
- 0.6.0
-
lastChild
public java.util.Optional<Node> lastChild()
Gets the last child.- Returns:
- an
Optionalholding the last child if thisContainerNodehas any children or otherwise and emptyOptional - Since:
- 0.6.0
-
getNode
@Deprecated public Node getNode(int index)
Deprecated.Usechild(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 java.util.Optional<Text> findTextNode()
- Returns:
- and
Optionalholding the first text node child or an emptyOptionalif there is no text child under thisContainerNode
-
textContent
public java.lang.String textContent()
- Returns:
- the text content of this node (concatenates all text children).
-
hasChildElements
public boolean hasChildElements()
- Returns:
trueif thisContainerNodehas any childElements orfalseotherwise
-
hasTextContent
public boolean hasTextContent()
- Returns:
trueif thisContainerNodehas any childTextnodes orfalseotherwise
-
isEmpty
public boolean isEmpty()
- Returns:
trueif thisContainerNodehas no child nodes orfalseotherwise
-
clearChildren
public void clearChildren()
Removes all child nodes from thisContainerNode.
-
clearModified
public void clearModified()
- Overrides:
clearModifiedin classNode
-
-