Package cdc.util.data
Interface Parent
-
-
Field Summary
-
Fields inherited from interface cdc.util.data.Node
ANY_NODE, ELEMENT_NAME_AND_ATTRIBUTES_COMPARATOR, ELEMENT_NAME_COMPARATOR, IS_COMMENT, IS_ELEMENT, IS_IGNORABLE_TEXT, IS_PURE_ELEMENT, IS_TEXT
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default <C extends Child>
CaddChild(C child)Adds a child to this parent.default voidaddChildren(Child... children)Adds all children of an array to this parent.default voidaddChildren(Iterable<? extends Child> children)Adds all children of an Iterable to this parent.default CommentaddComment(String content)Adds a comment as last child.default CommentaddComment(String content, boolean merge)Adds a comment as last child.default ElementaddElement(String name)Creates and adds a child element as last child, if possible.booleancanAddChild(Child child)Returnstruewhen a child can be added.default voidchangeComments(Function<String,String> modifier)Changes all comments locally.default voidchangeComments(Function<String,String> modifier, boolean recurse)Changes all comments recursively.default voidchangeNamedTexts(String name, Function<String,String> modifier)Changes or set text under element that have a given name, locally.default voidchangeNamedTexts(String name, Function<String,String> modifier, boolean recurse)Changes or set text under element that have a given name, recursively.default voidchangeTexts(Function<String,String> modifier)Changes all texts locally.default voidchangeTexts(Function<String,String> modifier, boolean recurse)Changes all texts recursively.Parentclone(boolean recurse)Return a clone of this node.default <T extends Node>
TgetChild(Class<T> childClass)default <T extends Node>
TgetChild(Class<T> childClass, Predicate<? super T> predicate)default ChildgetChildAt(int index)Returns the child at a given, index or null.default <T extends Node>
TgetChildAt(Class<T> childClass, int index)Returns the child that is an instance of a given class and is at a given position.default <T extends Node>
TgetChildAt(Class<T> childClass, Predicate<? super T> predicate, int index)Returns the child that is an instance of a given class, matches a Predicate and is at a given position.List<? extends Child>getChildren()default <T extends Node>
Iterable<T>getChildren(Class<T> childClass)Returns an Iterable of children that are instance of a given class.default <T extends Node>
Iterable<T>getChildren(Class<T> childClass, Predicate<? super T> predicate)Returns an Iterable of children that are instance of a given class and match a predicate.default intgetChildrenCount()default intgetChildrenCount(Class<? extends Node> childClass)Returns the number of children that match a class.default <T extends Node>
intgetChildrenCount(Class<T> childClass, Predicate<? super T> predicate)Returns the number of children that match a class and predicate.default Iterable<Comment>getComments()default ElementgetElementNamed(String name)Returns the first child element that has a given name ornull.default ElementgetElementNamedAt(String name, int index)Returns the child element that has a given name and index.default ElementgetElementNamedIgnoreCase(String name)Returns the first child element that has a given name, ignoring case, ornull.default ElementgetElementNamedIgnoreCaseAt(String name, int index)Returns the child element that has a given name, ignoring case, and index.default ElementgetElementNamedWithAttribute(String name, String attributeName, String attributeValue)default Iterable<Element>getElements()default Iterable<Element>getElementsNamed(String name)Returns an Iterable of children elements that have a given name.default Iterable<Element>getElementsNamedIgnoreCase(String name)Returns an Iterable of children elements that have a given name, ignoring case.default ChildgetLastChild()List<Child>getModifiableChildren()default Iterable<Text>getTexts()default booleanhasChildren()default booleanhasChildren(Class<? extends Node> childClass)Returnstrueif this parent has children of a given class.default <T extends Node>
booleanhasChildren(Class<T> childClass, Predicate<? super T> predicate)Returnstrueif this parent has children of a given class and matching a predicate.default booleanhasComments()default booleanhasElements()default booleanhasTexts()default voidmergeComments()Merges all consecutive comments locally.default voidmergeComments(boolean recurse)Merges all consecutive comments recursively.default voidmergeTexts()Merges all consecutive texts locally.default voidmergeTexts(boolean recurse)Merges all consecutive texts recursively.default booleanremoveChild(Child child)Remove a child.default ChildremoveChildAt(int index)Removes the child located at a given index.default voidremoveChildren()Removes all children locally.default voidremoveChildren(Predicate<? super Child> predicate)Removes all children that match a predicate.default voidremoveChildren(Predicate<? super Child> predicate, boolean pre, boolean recurse)Removes all children that match a predicate, recursively.default voidremoveComments()Removes all comments locally.default voidremoveComments(boolean recurse)Removes all comments recursively.default voidremoveElementsNamed(String name)Removes all children elements that have a given name.default voidremoveElementsNamed(String name, boolean recurse)Removes all children elements that have a given name, recursively.default voidremoveIgnorableTexts()Removes all ignorable texts locally.default voidremoveIgnorableTexts(boolean recurse)Removes all ignorable texts recursively.default voidremoveTexts()Removes all texts locally.default voidremoveTexts(boolean recurse)Removes all texts recursively.default voidsortChildren(Comparator<? super Child> comparator)Sorts children locally.default voidsortChildren(Comparator<? super Child> comparator, boolean recurse)Sorts children recursively.-
Methods inherited from interface cdc.util.data.Node
deepEquals, getDocument, getQName, getRootElement, getType
-
-
-
-
Method Detail
-
clone
Parent clone(boolean recurse)
Description copied from interface:NodeReturn a clone of this node.
-
canAddChild
boolean canAddChild(Child child)
Returnstruewhen a child can be added.- Parameters:
child- The child- Returns:
truewhenchildcan be added.
-
getChildren
default <T extends Node> Iterable<T> getChildren(Class<T> childClass)
Returns an Iterable of children that are instance of a given class.- Type Parameters:
T- Type of searched children.- Parameters:
childClass- The class of searched children.- Returns:
- An Iterable of children that are instance of
childClass.
-
getChildren
default <T extends Node> Iterable<T> getChildren(Class<T> childClass, Predicate<? super T> predicate)
Returns an Iterable of children that are instance of a given class and match a predicate.- Type Parameters:
T- Type of searched children.- Parameters:
childClass- The class of searched children.predicate- The predicate.- Returns:
- An Iterable of children that are instance of
childClassand matchpredicate.
-
getChildAt
default <T extends Node> T getChildAt(Class<T> childClass, Predicate<? super T> predicate, int index)
Returns the child that is an instance of a given class, matches a Predicate and is at a given position.- Type Parameters:
T- Type of searched children.- Parameters:
childClass- The class of searched children.predicate- The predicate.index- The index of the searched child. This index takes into account elements that matchchildClassandpredicate.- Returns:
- The element matching
childClassandpredicateand atindex, ornull.
-
getChildAt
default <T extends Node> T getChildAt(Class<T> childClass, int index)
Returns the child that is an instance of a given class and is at a given position.- Type Parameters:
T- Type of searched children.- Parameters:
childClass- The class of searched children.index- The index of the searched child. This index takes into account elements that matchchildClass.- Returns:
- The element matching
childClassand atindex, ornull.
-
hasElements
default boolean hasElements()
- Returns:
trueif this parent has children elements.
-
getElementsNamed
default Iterable<Element> getElementsNamed(String name)
Returns an Iterable of children elements that have a given name.- Parameters:
name- The name.- Returns:
- An Iterable containing elements named
name.
-
getElementNamedAt
default Element getElementNamedAt(String name, int index)
Returns the child element that has a given name and index.- Parameters:
name- The name.index- The index of the searched child element. This index takes into account children that are elements and are namedname.- Returns:
- The corresponding element or
null.
-
getElementNamed
default Element getElementNamed(String name)
Returns the first child element that has a given name ornull.- Parameters:
name- The name.- Returns:
- The first child element namedÂ
nameornull.
-
getElementsNamedIgnoreCase
default Iterable<Element> getElementsNamedIgnoreCase(String name)
Returns an Iterable of children elements that have a given name, ignoring case.- Parameters:
name- The name.- Returns:
- An Iterable containing elements named
nameignoring case.
-
getElementNamedIgnoreCaseAt
default Element getElementNamedIgnoreCaseAt(String name, int index)
Returns the child element that has a given name, ignoring case, and index.- Parameters:
name- The name.index- The index of the searched child element. This index takes into account children that are elements and are namednameignoring case.- Returns:
- The corresponding element or
null.
-
getElementNamedIgnoreCase
default Element getElementNamedIgnoreCase(String name)
Returns the first child element that has a given name, ignoring case, ornull.- Parameters:
name- The name.- Returns:
- The first child element namedÂ
name, ignoring case, ornull.
-
getElementNamedWithAttribute
default Element getElementNamedWithAttribute(String name, String attributeName, String attributeValue)
-
hasTexts
default boolean hasTexts()
- Returns:
trueif this parent has texts children.
-
hasComments
default boolean hasComments()
- Returns:
trueif this parent has comments children.
-
getChildrenCount
default <T extends Node> int getChildrenCount(Class<T> childClass, Predicate<? super T> predicate)
Returns the number of children that match a class and predicate.- Type Parameters:
T- Type of counted children.- Parameters:
childClass- The class of counted children.predicate- The predicate.- Returns:
- The number of children that match
childClassandpredicate.
-
getChildrenCount
default int getChildrenCount(Class<? extends Node> childClass)
Returns the number of children that match a class.- Parameters:
childClass- The class of counted children.- Returns:
- The number of children that match
childClass.
-
getChildrenCount
default int getChildrenCount()
- Returns:
- The number of children.
-
hasChildren
default <T extends Node> boolean hasChildren(Class<T> childClass, Predicate<? super T> predicate)
Returnstrueif this parent has children of a given class and matching a predicate.- Type Parameters:
T- Type of searched children.- Parameters:
childClass- The child class.predicate- The predicate.- Returns:
trueif this parent has children ofchildClassclass matchingpredicate.
-
hasChildren
default boolean hasChildren(Class<? extends Node> childClass)
Returnstrueif this parent has children of a given class.- Parameters:
childClass- The child class.- Returns:
trueif this parent has children ofchildClassclass.
-
hasChildren
default boolean hasChildren()
- Returns:
trueif this parent has children.
-
getChildAt
default Child getChildAt(int index)
Returns the child at a given, index or null.nullis returned when index is invalid.- Parameters:
index- The index.- Returns:
- The child at
index. - Throws:
IndexOutOfBoundsException- When index is out of range (index < 0 || index >= getChildrenCount()).
-
getLastChild
default Child getLastChild()
- Returns:
- The last child, if any, or
null.
-
addChild
default <C extends Child> C addChild(C child)
Adds a child to this parent.If possible, child current parent is changed to this node.
- Type Parameters:
C- Type of the child.- Parameters:
child- The child. MUST NOT be null.- Returns:
- The input
child. - Throws:
IllegalArgumentException- Ifchildisnull.IllegalStateException- Ifchild's parent can not be set.
-
addElement
default Element addElement(String name)
Creates and adds a child element as last child, if possible.- Parameters:
name- The child name.- Returns:
- the created element.
- Throws:
IllegalStateException- Ifchild's parent can not be set.
-
addComment
default Comment addComment(String content, boolean merge)
Adds a comment as last child.- Parameters:
content- The comment content.merge- Iftrue, then if last child exists and is a comment,contentis added to this last child.
Otherwise, a comment child is created and added to last position.- Returns:
- The modified or created comment.
-
addComment
default Comment addComment(String content)
Adds a comment as last child.If last child exists and is a comment,
contentis added to this last child.
Otherwise, a comment child is created and added to last position.- Parameters:
content- The comment content.- Returns:
- The modified or created comment.
-
addChildren
default void addChildren(Iterable<? extends Child> children)
Adds all children of an Iterable to this parent.- Parameters:
children- The children.
-
addChildren
default void addChildren(Child... children)
Adds all children of an array to this parent.- Parameters:
children- The children.
-
removeChild
default boolean removeChild(Child child)
Remove a child.If child is not a child of this parent, then false is returned.
- Parameters:
child- The child.- Returns:
trueif child was removed,falseotherwise.
-
removeChildAt
default Child removeChildAt(int index)
Removes the child located at a given index.If index is invalid, returns
false.- Parameters:
index- The index (0-based).- Returns:
- The removed child.
- Throws:
IndexOutOfBoundsException- When index is out of range (index < 0 || index >= getChildrenCount()).
-
removeChildren
default void removeChildren()
Removes all children locally.
-
removeChildren
default void removeChildren(Predicate<? super Child> predicate)
Removes all children that match a predicate.This does only a shallow removal.
For deep removal, useDataUtils.- Parameters:
predicate- The predicate.
-
removeChildren
default void removeChildren(Predicate<? super Child> predicate, boolean pre, boolean recurse)
Removes all children that match a predicate, recursively.- Parameters:
predicate- The predicate.pre- Iftrue, removal is applied before recursion, after otherwise.recurse- Iftrue, then this is applied recursively.
-
removeElementsNamed
default void removeElementsNamed(String name)
Removes all children elements that have a given name.- Parameters:
name- The name of elements to remove.
-
removeElementsNamed
default void removeElementsNamed(String name, boolean recurse)
Removes all children elements that have a given name, recursively.- Parameters:
name- The name of elements to remove.recurse- Iftrue, then this is applied recursively.
-
removeComments
default void removeComments()
Removes all comments locally.
-
removeComments
default void removeComments(boolean recurse)
Removes all comments recursively.- Parameters:
recurse- Iftrue, then this is applied recursively.
-
removeTexts
default void removeTexts()
Removes all texts locally.
-
removeTexts
default void removeTexts(boolean recurse)
Removes all texts recursively.- Parameters:
recurse- Iftrue, then this is applied recursively.
-
removeIgnorableTexts
default void removeIgnorableTexts()
Removes all ignorable texts locally.
-
removeIgnorableTexts
default void removeIgnorableTexts(boolean recurse)
Removes all ignorable texts recursively.- Parameters:
recurse- Iftrue, then this is applied recursively.
-
sortChildren
default void sortChildren(Comparator<? super Child> comparator)
Sorts children locally.- Parameters:
comparator- The comparator.
-
sortChildren
default void sortChildren(Comparator<? super Child> comparator, boolean recurse)
Sorts children recursively.- Parameters:
comparator- The comparator.recurse- Iftrue, then this is applied recursively.
-
mergeTexts
default void mergeTexts()
Merges all consecutive texts locally.
-
mergeTexts
default void mergeTexts(boolean recurse)
Merges all consecutive texts recursively.- Parameters:
recurse- Iftrue, then this is applied recursively.
-
mergeComments
default void mergeComments()
Merges all consecutive comments locally.
-
mergeComments
default void mergeComments(boolean recurse)
Merges all consecutive comments recursively.- Parameters:
recurse- Iftrue, then this is applied recursively.
-
changeTexts
default void changeTexts(Function<String,String> modifier)
Changes all texts locally.- Parameters:
modifier- A function that take content and returns new content.
-
changeTexts
default void changeTexts(Function<String,String> modifier, boolean recurse)
Changes all texts recursively.- Parameters:
modifier- A function that take content and returns new content.recurse- Iftrue, then this is applied recursively.
-
changeNamedTexts
default void changeNamedTexts(String name, Function<String,String> modifier)
Changes or set text under element that have a given name, locally.This will work on elements that are empty or have text and comment children.
It will ignore elements that have children elements.Children nodes are preserved if possible.
Otherwise, they are all removed and replace if necessary.
WARNING: This may remove comments.- Parameters:
name- The element name.modifier- A function that take content and returns new content.
-
changeNamedTexts
default void changeNamedTexts(String name, Function<String,String> modifier, boolean recurse)
Changes or set text under element that have a given name, recursively.- Parameters:
name- The element name.modifier- A function that take content and returns new content.recurse- Iftrue, then this is applied recursively.
-
changeComments
default void changeComments(Function<String,String> modifier)
Changes all comments locally.- Parameters:
modifier- A function that take content and returns new content.
-
-