Package com.helger.xml.microdom
Class AbstractMicroNodeWithChildren
- java.lang.Object
-
- com.helger.xml.microdom.AbstractMicroNode
-
- com.helger.xml.microdom.AbstractMicroNodeWithChildren
-
- All Implemented Interfaces:
com.helger.commons.hierarchy.IHasChildren<IMicroNode>,com.helger.commons.hierarchy.IHasChildrenRecursive<IMicroNode>,com.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>,com.helger.commons.hierarchy.IHasParent<IMicroNode>,com.helger.commons.lang.ICloneable<IMicroNode>,IMicroNode,IMicroNodeWithChildren,Serializable
- Direct Known Subclasses:
MicroContainer,MicroDocument,MicroElement
public abstract class AbstractMicroNodeWithChildren extends AbstractMicroNode implements IMicroNodeWithChildren
Basic implementation class for the micro document object model. It overrides all methods required for correct parent/child handling.- Author:
- Philip Helger
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description AbstractMicroNodeWithChildren()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsAnyChild(Predicate<? super IMicroNode> aFilter)Check if any direct child matching the provided filter is contained.protected com.helger.commons.collection.impl.ICommonsList<IMicroNode>directGetAllChildren()IMicroNodefindFirstChild(Predicate<? super IMicroNode> aFilter)<DSTTYPE> DSTTYPEfindFirstChildMapped(Predicate<? super IMicroNode> aFilter, Function<? super IMicroNode,? extends DSTTYPE> aMapper)voidforAllChildren(Consumer<? super IMicroNode> aConsumer)voidforAllChildren(Predicate<? super IMicroNode> aFilter, Consumer<? super IMicroNode> aConsumer)com.helger.commons.state.EContinueforAllChildrenBreakable(Function<? super IMicroNode,com.helger.commons.state.EContinue> aConsumer)<DSTTYPE> voidforAllChildrenMapped(Predicate<? super IMicroNode> aFilter, Function<? super IMicroNode,? extends DSTTYPE> aMapper, Consumer<? super DSTTYPE> aConsumer)com.helger.commons.collection.impl.ICommonsList<IMicroNode>getAllChildren()Get a list of all direct child nodes.IMicroNodegetChildAtIndex(int nIndex)intgetChildCount()com.helger.commons.collection.impl.ICommonsIterable<IMicroNode>getChildren()IMicroNodegetFirstChild()IMicroNodegetLastChild()StringgetTextContent()Get the concatenated text content of all directIMicroTextchild nodes of this element.<DSTTYPE> DSTTYPEgetTextContentWithConversion(Class<DSTTYPE> aDstClass)Get the concatenated text content of all directIMicroTextchild nodes of this element.booleanhasChildren()booleanisEqualContent(IMicroNode o)As instances of this class may not implement equals/hashCode we need a way to determine, if 2 nodes are equal by content.protected voidonAppendChild(AbstractMicroNode aChildNode)Callback that is invoked once a child is to be appended.protected voidonInsertAfter(AbstractMicroNode aChildNode, IMicroNode aPredecessor)Callback that is invoked once a child is to be inserted after another child.protected voidonInsertAtIndex(int nIndex, AbstractMicroNode aChildNode)Callback that is invoked once a child is to be inserted at the specified index.protected voidonInsertBefore(AbstractMicroNode aChildNode, IMicroNode aSuccessor)Callback that is invoked once a child is to be inserted before another child.protected com.helger.commons.state.EChangeonRemoveAllChildren()Remove all children from this node.protected com.helger.commons.state.EChangeonRemoveChild(IMicroNode aChildNode)Callback when a child is removed.protected com.helger.commons.state.EChangeonRemoveChildAtIndex(int nIndex)Remove the child not at the specified index.StringtoString()-
Methods inherited from class com.helger.xml.microdom.AbstractMicroNode
appendChild, detachFromParent, findParentElement, getAllEventTargets, getAllEventTargets, getNextSibling, getParent, getPreviousSibling, hasParent, insertAfter, insertAtIndex, insertBefore, internalResetParentNode, internalSetParentNode, internalTriggerEvent, isCDATA, isComment, isContainer, isDocument, isDocumentType, isElement, isEntityReference, isProcessingInstruction, isText, onEvent, registerEventTarget, removeAllChildren, removeChild, removeChildAtIndex, unregisterEventTarget
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.hierarchy.IHasChildrenRecursive
forAllChildrenRecursive, forAllChildrenRecursive
-
Methods inherited from interface com.helger.xml.microdom.IMicroNode
appendCDATA, appendCDATA, appendCDATA, appendCDATAWithConversion, appendChild, appendChildren, appendChildren, appendComment, appendComment, appendComment, appendCommentWithConversion, appendContainer, appendElement, appendElement, appendEntityReference, appendIgnorableWhitespaceText, appendIgnorableWhitespaceText, appendIgnorableWhitespaceText, appendProcessingInstruction, appendText, appendText, appendText, appendTextWithConversion, detachFromParent, findParentElement, getAllChildrenRecursive, getAllEventTargets, getAllEventTargets, getNextSibling, getNodeName, getNodeValue, getParent, getParentElementWithName, getParentElementWithName, getPreviousSibling, getType, hasParent, insertAfter, insertAtIndex, insertBefore, isCDATA, isComment, isContainer, isDocument, isDocumentType, isElement, isEntityReference, isProcessingInstruction, isText, registerEventTarget, removeAllChildren, removeChild, removeChildAtIndex, replaceChild, unregisterEventTarget
-
Methods inherited from interface com.helger.xml.microdom.IMicroNodeWithChildren
getClone, getTextContentTrimmed
-
-
-
-
Method Detail
-
directGetAllChildren
@Nullable @ReturnsMutableObject("efficient access") protected final com.helger.commons.collection.impl.ICommonsList<IMicroNode> directGetAllChildren()
- Returns:
- The writable list of all child nodes - handle with care. May be
null.
-
onAppendChild
protected void onAppendChild(@Nonnull AbstractMicroNode aChildNode)
Description copied from class:AbstractMicroNodeCallback that is invoked once a child is to be appended.- Overrides:
onAppendChildin classAbstractMicroNode- Parameters:
aChildNode- The appended child node.
-
onInsertBefore
protected final void onInsertBefore(@Nonnull AbstractMicroNode aChildNode, @Nonnull IMicroNode aSuccessor)
Description copied from class:AbstractMicroNodeCallback that is invoked once a child is to be inserted before another child.- Overrides:
onInsertBeforein classAbstractMicroNode- Parameters:
aChildNode- The new child node to be inserted.aSuccessor- The node before which the new node will be inserted.
-
onInsertAfter
protected final void onInsertAfter(@Nonnull AbstractMicroNode aChildNode, @Nonnull IMicroNode aPredecessor)
Description copied from class:AbstractMicroNodeCallback that is invoked once a child is to be inserted after another child.- Overrides:
onInsertAfterin classAbstractMicroNode- Parameters:
aChildNode- The new child node to be inserted.aPredecessor- The node after which the new node will be inserted.
-
onInsertAtIndex
protected final void onInsertAtIndex(@Nonnegative int nIndex, @Nonnull AbstractMicroNode aChildNode)
Description copied from class:AbstractMicroNodeCallback that is invoked once a child is to be inserted at the specified index.- Overrides:
onInsertAtIndexin classAbstractMicroNode- Parameters:
nIndex- The index where the node should be inserted.aChildNode- The new child node to be inserted.
-
onRemoveChild
@Nonnull protected final com.helger.commons.state.EChange onRemoveChild(@Nonnull IMicroNode aChildNode)
Description copied from class:AbstractMicroNodeCallback when a child is removed.- Overrides:
onRemoveChildin classAbstractMicroNode- Parameters:
aChildNode- The child that is removed.- Returns:
EChange.CHANGEDif something changed
-
onRemoveChildAtIndex
@Nonnull protected final com.helger.commons.state.EChange onRemoveChildAtIndex(@Nonnegative int nIndex)
Description copied from class:AbstractMicroNodeRemove the child not at the specified index.- Overrides:
onRemoveChildAtIndexin classAbstractMicroNode- Parameters:
nIndex- The 0-based index of the item to be removed.- Returns:
EChange.CHANGEDif the node was successfully removed,EChange.UNCHANGEDotherwise.
-
onRemoveAllChildren
@Nonnull protected final com.helger.commons.state.EChange onRemoveAllChildren()
Description copied from class:AbstractMicroNodeRemove all children from this node.- Overrides:
onRemoveAllChildrenin classAbstractMicroNode- Returns:
EChange.CHANGEDif at least one child was present, and was successfully removed,EChange.UNCHANGEDotherwise.
-
hasChildren
public final boolean hasChildren()
- Specified by:
hasChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>- Overrides:
hasChildrenin classAbstractMicroNode
-
getAllChildren
@Nullable @ReturnsMutableCopy public final com.helger.commons.collection.impl.ICommonsList<IMicroNode> getAllChildren()
Description copied from interface:IMicroNodeGet a list of all direct child nodes.- Specified by:
getAllChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>- Specified by:
getAllChildrenin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>- Specified by:
getAllChildrenin interfaceIMicroNode- Overrides:
getAllChildrenin classAbstractMicroNode- Returns:
- May be
nullif the node has no children.
-
getChildren
@Nullable public final com.helger.commons.collection.impl.ICommonsIterable<IMicroNode> getChildren()
- Specified by:
getChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>- Overrides:
getChildrenin classAbstractMicroNode
-
forAllChildren
public final void forAllChildren(@Nonnull Consumer<? super IMicroNode> aConsumer)
- Specified by:
forAllChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>- Overrides:
forAllChildrenin classAbstractMicroNode
-
forAllChildrenBreakable
@Nonnull public com.helger.commons.state.EContinue forAllChildrenBreakable(@Nonnull Function<? super IMicroNode,com.helger.commons.state.EContinue> aConsumer)
- Specified by:
forAllChildrenBreakablein interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>- Overrides:
forAllChildrenBreakablein classAbstractMicroNode
-
forAllChildren
public final void forAllChildren(@Nonnull Predicate<? super IMicroNode> aFilter, @Nonnull Consumer<? super IMicroNode> aConsumer)
- Specified by:
forAllChildrenin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>- Overrides:
forAllChildrenin classAbstractMicroNode
-
forAllChildrenMapped
public final <DSTTYPE> void forAllChildrenMapped(@Nonnull Predicate<? super IMicroNode> aFilter, @Nonnull Function<? super IMicroNode,? extends DSTTYPE> aMapper, @Nonnull Consumer<? super DSTTYPE> aConsumer)
- Specified by:
forAllChildrenMappedin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>- Overrides:
forAllChildrenMappedin classAbstractMicroNode
-
containsAnyChild
public boolean containsAnyChild(@Nonnull Predicate<? super IMicroNode> aFilter)
Description copied from interface:IMicroNodeCheck if any direct child matching the provided filter is contained.- Specified by:
containsAnyChildin interfaceIMicroNode- Parameters:
aFilter- The filter that is applied to all child nodes. May not benull.- Returns:
trueif any child matching the provided filter is contained,falseotherwise.
-
getChildAtIndex
@Nullable public final IMicroNode getChildAtIndex(@Nonnegative int nIndex)
- Specified by:
getChildAtIndexin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>- Overrides:
getChildAtIndexin classAbstractMicroNode
-
getChildCount
public final int getChildCount()
- Specified by:
getChildCountin interfacecom.helger.commons.hierarchy.IHasChildren<IMicroNode>- Overrides:
getChildCountin classAbstractMicroNode
-
getFirstChild
@Nullable public final IMicroNode getFirstChild()
- Specified by:
getFirstChildin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>- Specified by:
getFirstChildin interfaceIMicroNode- Overrides:
getFirstChildin classAbstractMicroNode- Returns:
- The first child node of this node, or
nullif this node has no children.
-
findFirstChild
@Nullable public final IMicroNode findFirstChild(@Nonnull Predicate<? super IMicroNode> aFilter)
- Specified by:
findFirstChildin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>- Overrides:
findFirstChildin classAbstractMicroNode
-
findFirstChildMapped
@Nullable public final <DSTTYPE> DSTTYPE findFirstChildMapped(@Nonnull Predicate<? super IMicroNode> aFilter, @Nonnull Function<? super IMicroNode,? extends DSTTYPE> aMapper)
- Specified by:
findFirstChildMappedin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>- Overrides:
findFirstChildMappedin classAbstractMicroNode
-
getLastChild
@Nullable public final IMicroNode getLastChild()
- Specified by:
getLastChildin interfacecom.helger.commons.hierarchy.IHasChildrenSorted<IMicroNode>- Specified by:
getLastChildin interfaceIMicroNode- Overrides:
getLastChildin classAbstractMicroNode- Returns:
- The last child node of this node, or
nullif this node has no children.
-
getTextContent
@Nullable public String getTextContent()
Description copied from interface:IMicroNodeWithChildrenGet the concatenated text content of all directIMicroTextchild nodes of this element.- Specified by:
getTextContentin interfaceIMicroNodeWithChildren- Returns:
nullif the element contains no text node as child
-
getTextContentWithConversion
@Nullable public <DSTTYPE> DSTTYPE getTextContentWithConversion(@Nonnull Class<DSTTYPE> aDstClass)
Description copied from interface:IMicroNodeWithChildrenGet the concatenated text content of all directIMicroTextchild nodes of this element. The value is converted via theTypeConverterto the desired destination class.- Specified by:
getTextContentWithConversionin interfaceIMicroNodeWithChildren- Type Parameters:
DSTTYPE- The destination type to convert the String textContent to.- Parameters:
aDstClass- The destination class to which the text content should be converted.- Returns:
nullif the element contains no text node as child
-
isEqualContent
@OverridingMethodsMustInvokeSuper public boolean isEqualContent(@Nullable IMicroNode o)
Description copied from interface:IMicroNodeAs instances of this class may not implement equals/hashCode we need a way to determine, if 2 nodes are equal by content.- Specified by:
isEqualContentin interfaceIMicroNode- Parameters:
o- The node to compare to this.- Returns:
trueif the nodes are of the same type and the same content,falseotherwise.
-
toString
public String toString()
- Overrides:
toStringin classAbstractMicroNode
-
-