Package cdc.util.data
Class Element
- java.lang.Object
-
- cdc.util.data.AbstractChild
-
- cdc.util.data.Element
-
public final class Element extends AbstractChild implements Parent
XML like Element node.It has a name, can have children (elements, comments or texts).
It can also have attributes.- Author:
- Damien Carbonne
-
-
Field Summary
Fields Modifier and Type Field Description static Comparator<Element>NAME_COMPARATORA comparator of elements using their names.-
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 Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttribute(Attribute attribute)Adds an attribute.voidaddAttribute(String name, boolean value)Adds a boolean attribute.voidaddAttribute(String name, byte value)Adds a byte attribute.voidaddAttribute(String name, double value)Adds a double attribute.voidaddAttribute(String name, float value)Adds a float attribute.voidaddAttribute(String name, int value)Adds an int attribute.voidaddAttribute(String name, long value)Adds a long attribute.voidaddAttribute(String name, short value)Adds a short attribute.voidaddAttribute(String name, Object value)Adds an object attribute.voidaddAttribute(String name, String value)Adds a string attribute.voidaddAttributes(Attribute... attributes)Adds an array of attributes to this element.voidaddAttributes(Collection<Attribute> attributes)Adds all attributes of a collection to this element.TextaddText(String content)Adds a text as last child.TextaddText(String content, boolean merge)Adds a text as last child.booleancanAddChild(Child child)Returnstruewhen a child can be added.voidchangeAttributeValue(String name, UnaryOperator<String> modifier)Changes the value of attributes that have a given name.voidchangeAttributeValue(String name, UnaryOperator<String> modifier, boolean recurse)Changes the value of attributes that have a given name.voidchangeName(UnaryOperator<String> modifier)Changes the element name.voidchangeName(UnaryOperator<String> modifier, boolean recurse)Changes element names recursively.Elementclone(boolean recurse)Return a clone of this node.static Comparator<Element>compareAttribute(String attributeName)Returns a comparator that compares the values of a particular attribute.static Comparator<Element>compareNameAndAttribute(String attributeName)Returns a comparator that compares the names then the values of a particular attribute.booleandeepEquals(Node node)Return true when this node and its descendants equals other node hierarchy.AttributegetAttribute(String name)Returns the attribute that has a particular name, ornull.booleangetAttributeAsBoolean(String name, boolean def)Returns the value associated to an attribute as a boolean or a default value.bytegetAttributeAsByte(String name, byte def)Returns the value associated to an attribute as a byte.doublegetAttributeAsDouble(String name, double def)Returns the value associated to an attribute as a double.<E extends Enum<E>>
EgetAttributeAsEnum(String name, Class<E> enumClass, E def)Returns the value associated to an attribute as an enum.floatgetAttributeAsFloat(String name, float def)Returns the value associated to an attribute as a float.intgetAttributeAsInt(String name, int def)Returns the value associated to an attribute as an int.longgetAttributeAsLong(String name, long def)Returns the value associated to an attribute as a long.BooleangetAttributeAsOptionalBoolean(String name, Boolean def)Returns the value associated to an attribute as a Boolean or a default value.BytegetAttributeAsOptionalByte(String name, Byte def)Returns the value associated to an attribute as a Byte.DoublegetAttributeAsOptionalDouble(String name, Double def)Returns the value associated to an attribute as a Double.<E extends Enum<E>>
EgetAttributeAsOptionalEnum(String name, Class<E> enumClass, E def)FloatgetAttributeAsOptionalFloat(String name, Float def)Returns the value associated to an attribute as a Float.IntegergetAttributeAsOptionalInt(String name, Integer def)Returns the value associated to an attribute as an Integer.LonggetAttributeAsOptionalLong(String name, Long def)Returns the value associated to an attribute as a Long.Enum<?>getAttributeAsOptionalRawEnum(String name, Class<? extends Enum<?>> enumClass, Enum<?> def)ShortgetAttributeAsOptionalShort(String name, Short def)Returns the value associated to an attribute as a Short.Enum<?>getAttributeAsRawEnum(String name, Class<? extends Enum<?>> enumClass, Enum<?> def)shortgetAttributeAsShort(String name, short def)Returns the value associated to an attribute as a short.AttributegetAttributeAt(int index)Returns the attribute at a given index.intgetAttributeIndex(String name)Returns the index of the attribute that has a particular name or -1.List<Attribute>getAttributes()intgetAttributesCount()StringgetAttributeValue(String name)Returns the value associated to an attribute as a string ornull.StringgetAttributeValue(String name, String def)Returns the value associated to an attribute as a string or a default value.StringgetAttributeValue(String name, String def, FailureReaction missingReaction)Returns the value associated to an attribute.List<Child>getChildren()ElementContentTypegetContentType()StringgetElementNamedText(String name)Returns the text content of the first child element that has a given name.StringgetElementNamedText(String name, String def)Returns the text content of the first child element that has a given name.List<Child>getModifiableChildren()StringgetName()StringgetQName()List<Attribute>getSortedAttributes()StringgetText()Returns the merged content of all children text nodes, if this node has no element children.StringgetText(String def)Returns the merged content of all children text nodes, if this node has no element children.booleangetTextAsBoolean(boolean def)bytegetTextAsByte(byte def)doublegetTextAsDouble(double def)<E extends Enum<E>>
EgetTextAsEnum(Class<E> enumClass, E def)floatgetTextAsFloat(float def)intgetTextAsInt(int def)longgetTextAsLong(long def)BooleangetTextAsOptionalBoolean(Boolean def)BytegetTextAsOptionalByte(Byte def)DoublegetTextAsOptionalDouble(Double def)<E extends Enum<E>>
EgetTextAsOptionalEnum(Class<E> enumClass, E def)FloatgetTextAsOptionalFloat(Float def)IntegergetTextAsOptionalInt(Integer def)LonggetTextAsOptionalLong(Long def)ShortgetTextAsOptionalShort(Short def)shortgetTextAsShort(short def)NodeTypegetType()booleanhasAttribute(String name)Returnstruewhen an attribute with a particular name exists.static Predicate<Node>hasAttribute(String attributeName, String attributeValue)Creates a Predicate that accepts Nodes that are elements that have an attribute with a given value.booleanhasAttributes()booleanhasChildren()booleanhasOnlyNonText()booleanhasOnlyText()booleanisEmpty()booleanisMixed()booleanisPure()booleanisRoot()static Predicate<Node>matching(Set<SPath> paths)static Predicate<Node>named(String name)Creates a Predicate that accepts Nodes that are element with a given name.static Predicate<Node>named(String... names)Creates a Predicate that accepts Nodes that are element whose named belongs to an array.static Predicate<Node>named(Set<String> names)Creates a Predicate that accepts Nodes that are element whose named belongs to a set.static Predicate<Node>namedIgnoreCase(String name)Creates a Predicate that accepts Nodes that are element with a given name, ignoring case.static Predicate<Node>namedWithAttribute(String name, String attributeName, String attributeValue)Creates a Predicate that accepts Nodes that are elements with a given name and have an attribute with a given value.AttributeremoveAttribute(String name)Removes an attribute identified by its name.voidremoveAttributes()Remove all attributes of this element.voidremoveAttributes(Predicate<Attribute> predicate)voidremoveAttributes(Predicate<Attribute> predicate, boolean recurse)voidremoveAttributesNamed(String name)voidremoveAttributesNamed(String... names)voidremoveAttributesNamed(String name, boolean recurse)voidremoveAttributesNamed(Set<String> names)voidremoveAttributesNamed(Set<String> names, boolean recurse)voidsetName(String name)Sets the name of this element.StringtoString()-
Methods inherited from class cdc.util.data.AbstractChild
equals, getDocument, getParent, getRootElement, hashCode, resetParent, setParent
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface cdc.util.data.Child
detach, getIndex, getParent, getRootChild, setIndex
-
Methods inherited from interface cdc.util.data.Node
getDocument, getRootElement
-
Methods inherited from interface cdc.util.data.Parent
addChild, addChildren, addChildren, addComment, addComment, addElement, changeComments, changeComments, changeNamedTexts, changeNamedTexts, changeTexts, changeTexts, getChild, getChild, getChildAt, getChildAt, getChildAt, getChildren, getChildren, getChildrenCount, getChildrenCount, getChildrenCount, getComments, getElementNamed, getElementNamedAt, getElementNamedIgnoreCase, getElementNamedIgnoreCaseAt, getElementNamedWithAttribute, getElements, getElementsNamed, getElementsNamedIgnoreCase, getLastChild, getTexts, hasChildren, hasChildren, hasComments, hasElements, hasTexts, mergeComments, mergeComments, mergeTexts, mergeTexts, removeChild, removeChildAt, removeChildren, removeChildren, removeChildren, removeComments, removeComments, removeElementsNamed, removeElementsNamed, removeIgnorableTexts, removeIgnorableTexts, removeTexts, removeTexts, sortChildren, sortChildren
-
-
-
-
Field Detail
-
NAME_COMPARATOR
public static final Comparator<Element> NAME_COMPARATOR
A comparator of elements using their names.
-
-
Constructor Detail
-
Element
public Element(String name)
Creates an element.- Parameters:
name- The element name.- Throws:
IllegalArgumentException- Whennameis invalid.
-
Element
public Element(Parent parent, String name)
Creates an element.- Parameters:
parent- The element's parent.name- The element name.- Throws:
IllegalArgumentException- Whennameis invalid.IllegalStateException- Whenparentcan not not be set.
-
Element
public Element(Element other)
Creates an element by cloning another one.Cloning is shallow.
For deep cloning, useclone(boolean).- Parameters:
other- The element to clone.
-
-
Method Detail
-
compareAttribute
public static Comparator<Element> compareAttribute(String attributeName)
Returns a comparator that compares the values of a particular attribute.- Parameters:
attributeName- The name of the attribute to use.- Returns:
- A comparator comparing the value of attributes named
attributeName.
-
compareNameAndAttribute
public static Comparator<Element> compareNameAndAttribute(String attributeName)
Returns a comparator that compares the names then the values of a particular attribute.- Parameters:
attributeName- The name of the attribute to use.- Returns:
- A comparator that compares the names then the values of attributes named
attributeName.
-
clone
public Element clone(boolean recurse)
Description copied from interface:NodeReturn a clone of this node.
-
deepEquals
public boolean deepEquals(Node node)
Description copied from interface:NodeReturn true when this node and its descendants equals other node hierarchy.Parents are ignored.
- Specified by:
deepEqualsin interfaceNode- Parameters:
node- The other node to compare.- Returns:
- True when this node and other node have same hierarchies.
-
getQName
public String getQName()
-
canAddChild
public boolean canAddChild(Child child)
Description copied from interface:ParentReturnstruewhen a child can be added.- Specified by:
canAddChildin interfaceParent- Parameters:
child- The child- Returns:
truewhenchildcan be added.
-
hasChildren
public boolean hasChildren()
- Specified by:
hasChildrenin interfaceParent- Returns:
trueif this parent has children.
-
getModifiableChildren
public List<Child> getModifiableChildren()
- Specified by:
getModifiableChildrenin interfaceParent
-
getChildren
public List<Child> getChildren()
- Specified by:
getChildrenin interfaceParent- Returns:
- A list of children.
-
setName
public void setName(String name)
Sets the name of this element.- Parameters:
name- The name.- Throws:
IllegalArgumentException- Whennameis invalid.
-
getName
public String getName()
- Returns:
- the name of this element.
-
getContentType
public ElementContentType getContentType()
- Returns:
- The content type of this element.
-
isEmpty
public boolean isEmpty()
- Returns:
trueif this element has no children. It may have attributes.
-
isPure
public boolean isPure()
- Returns:
trueif this element is empty and has no attributes.
-
hasOnlyText
public boolean hasOnlyText()
- Returns:
trueif this element has only text children.
-
hasOnlyNonText
public boolean hasOnlyNonText()
- Returns:
trueif this element has only non-text (comments and elements) children.
-
isMixed
public boolean isMixed()
- Returns:
trueif this element has text and non-text children.
-
isRoot
public boolean isRoot()
- Returns:
trueif this element is a root element.
-
getSortedAttributes
public List<Attribute> getSortedAttributes()
- Returns:
- A list of attributes of this element, sorted by names.
-
getAttributesCount
public int getAttributesCount()
- Returns:
- The number of attributes of this element.
-
hasAttributes
public boolean hasAttributes()
- Returns:
trueif this element has attributes.
-
getAttributeAt
public Attribute getAttributeAt(int index)
Returns the attribute at a given index.- Parameters:
index- The index.- Returns:
- The attribute at
index. - Throws:
IndexOutOfBoundsException- If the index is out of range(index < 0 || index >= getAttributesCount())
-
hasAttribute
public boolean hasAttribute(String name)
Returnstruewhen an attribute with a particular name exists.- Parameters:
name- The name.- Returns:
truewhen an attribute namednameexists.
-
getAttribute
public Attribute getAttribute(String name)
Returns the attribute that has a particular name, ornull.- Parameters:
name- The name.- Returns:
- The attribute named
nameornull.
-
getAttributeIndex
public int getAttributeIndex(String name)
Returns the index of the attribute that has a particular name or -1.- Parameters:
name- The name.- Returns:
- The index of attribute named
nameor -1.
-
getAttributeValue
public String getAttributeValue(String name, String def, FailureReaction missingReaction)
Returns the value associated to an attribute.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists.missingReaction- The reaction to adopt when attribute is not found.- Returns:
- The value of attribute named
nameordef. - Throws:
NotFoundException- when attribute is not found andmissingReactionisFailureReaction.FAIL.
-
getAttributeValue
public String getAttributeValue(String name, String def)
Returns the value associated to an attribute as a string or a default value.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists.- Returns:
- The value of attribute named
nameordef.
-
getAttributeValue
public String getAttributeValue(String name)
Returns the value associated to an attribute as a string ornull.- Parameters:
name- The attribute name.- Returns:
- The value of attribute named
name. - Throws:
NotFoundException- when attribute is not found.
-
getAttributeAsBoolean
public boolean getAttributeAsBoolean(String name, boolean def)
Returns the value associated to an attribute as a boolean or a default value.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to a boolean.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to a boolean, thendefis returned and a warning is issued.
-
getAttributeAsOptionalBoolean
public Boolean getAttributeAsOptionalBoolean(String name, Boolean def)
Returns the value associated to an attribute as a Boolean or a default value.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to a Boolean.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to a Boolean, thendefis returned and a warning is issued.
-
getAttributeAsLong
public long getAttributeAsLong(String name, long def)
Returns the value associated to an attribute as a long.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to a long.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to a long, thendefis returned and a warning is issued.
-
getAttributeAsOptionalLong
public Long getAttributeAsOptionalLong(String name, Long def)
Returns the value associated to an attribute as a Long.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to a Long.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to a Long, thendefis returned and a warning is issued.
-
getAttributeAsInt
public int getAttributeAsInt(String name, int def)
Returns the value associated to an attribute as an int.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to an int.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to an int, thendefis returned and a warning is issued.
-
getAttributeAsOptionalInt
public Integer getAttributeAsOptionalInt(String name, Integer def)
Returns the value associated to an attribute as an Integer.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to an Integer.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to an Integer, thendefis returned and a warning is issued.
-
getAttributeAsShort
public short getAttributeAsShort(String name, short def)
Returns the value associated to an attribute as a short.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to a short.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to a short, thendefis returned and a warning is issued.
-
getAttributeAsOptionalShort
public Short getAttributeAsOptionalShort(String name, Short def)
Returns the value associated to an attribute as a Short.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to a Short.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to a Short, thendefis returned and a warning is issued.
-
getAttributeAsByte
public byte getAttributeAsByte(String name, byte def)
Returns the value associated to an attribute as a byte.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to a byte.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to a byte, thendefis returned and a warning is issued.
-
getAttributeAsOptionalByte
public Byte getAttributeAsOptionalByte(String name, Byte def)
Returns the value associated to an attribute as a Byte.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to a Byte.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to a Byte, thendefis returned and a warning is issued.
-
getAttributeAsDouble
public double getAttributeAsDouble(String name, double def)
Returns the value associated to an attribute as a double.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to a double.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to a double, thendefis returned and a warning is issued.
-
getAttributeAsOptionalDouble
public Double getAttributeAsOptionalDouble(String name, Double def)
Returns the value associated to an attribute as a Double.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to a Double.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to a Double, thendefis returned and a warning is issued.
-
getAttributeAsFloat
public float getAttributeAsFloat(String name, float def)
Returns the value associated to an attribute as a float.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to a float.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to a float, thendefis returned and a warning is issued.
-
getAttributeAsOptionalFloat
public Float getAttributeAsOptionalFloat(String name, Float def)
Returns the value associated to an attribute as a Float.- Parameters:
name- The attribute name.def- The value to return if no attribute namednameexists or if its value can not be converted to a Float.- Returns:
- The value of attribute named
nameordef.
If the attribute exists but its value can not be converted to a Float, thendefis returned and a warning is issued.
-
getAttributeAsRawEnum
public Enum<?> getAttributeAsRawEnum(String name, Class<? extends Enum<?>> enumClass, Enum<?> def)
-
getAttributeAsOptionalRawEnum
public Enum<?> getAttributeAsOptionalRawEnum(String name, Class<? extends Enum<?>> enumClass, Enum<?> def)
-
getAttributeAsEnum
public <E extends Enum<E>> E getAttributeAsEnum(String name, Class<E> enumClass, E def)
Returns the value associated to an attribute as an enum.- Type Parameters:
E- The enum type.- Parameters:
name- The attribute name.enumClass- The enum class.def- The value to return if no attribute namednameexists or if its value can not be converted to an enum.- Returns:
- The value of attribute named
nameordef.
-
getAttributeAsOptionalEnum
public <E extends Enum<E>> E getAttributeAsOptionalEnum(String name, Class<E> enumClass, E def)
-
addAttribute
public void addAttribute(Attribute attribute)
Adds an attribute.- Parameters:
attribute- The attribute.- Throws:
IllegalArgumentException- Whenattributeis invalid or another attribute with same name already exists.
-
addAttributes
public void addAttributes(Collection<Attribute> attributes)
Adds all attributes of a collection to this element.- Parameters:
attributes- The attributes to add.- Throws:
IllegalArgumentException- When one ofattributesis invalid or another attribute with same name already exists.
-
addAttributes
public void addAttributes(Attribute... attributes)
Adds an array of attributes to this element.- Parameters:
attributes- The attributes to add.- Throws:
IllegalArgumentException- When one ofattributesis invalid or another attribute with same name already exists.
-
addAttribute
public void addAttribute(String name, Object value)
Adds an object attribute.The string value is constructed using value.toString().
- Parameters:
name- The attribute name.value- The attribute value.- Throws:
IllegalArgumentException- Whennameis invalid or another attribute with same name already exists.
-
addAttribute
public void addAttribute(String name, String value)
Adds a string attribute.- Parameters:
name- The attribute name.value- The attribute value.- Throws:
IllegalArgumentException- Whennameis invalid or another attribute with same name already exists.
-
addAttribute
public void addAttribute(String name, boolean value)
Adds a boolean attribute.- Parameters:
name- The attribute name.value- The attribute value.- Throws:
IllegalArgumentException- Whennameis invalid or another attribute with same name already exists.
-
addAttribute
public void addAttribute(String name, long value)
Adds a long attribute.- Parameters:
name- The attribute name.value- The attribute value.- Throws:
IllegalArgumentException- Whennameis invalid or another attribute with same name already exists.
-
addAttribute
public void addAttribute(String name, int value)
Adds an int attribute.- Parameters:
name- The attribute name.value- The attribute value.- Throws:
IllegalArgumentException- Whennameis invalid or another attribute with same name already exists.
-
addAttribute
public void addAttribute(String name, short value)
Adds a short attribute.- Parameters:
name- The attribute name.value- The attribute value.- Throws:
IllegalArgumentException- Whennameis invalid or another attribute with same name already exists.
-
addAttribute
public void addAttribute(String name, byte value)
Adds a byte attribute.- Parameters:
name- The attribute name.value- The attribute value.- Throws:
IllegalArgumentException- Whennameis invalid or another attribute with same name already exists.
-
addAttribute
public void addAttribute(String name, double value)
Adds a double attribute.- Parameters:
name- The attribute name.value- The attribute value.- Throws:
IllegalArgumentException- Whennameis invalid or another attribute with same name already exists.
-
addAttribute
public void addAttribute(String name, float value)
Adds a float attribute.- Parameters:
name- The attribute name.value- The attribute value.- Throws:
IllegalArgumentException- Whennameis invalid or another attribute with same name already exists.
-
removeAttribute
public Attribute removeAttribute(String name)
Removes an attribute identified by its name.- Parameters:
name- The name of the attribute to remove.- Returns:
- The removed attribute or null.
-
removeAttributesNamed
public void removeAttributesNamed(String name)
-
removeAttributesNamed
public void removeAttributesNamed(String name, boolean recurse)
-
removeAttributesNamed
public void removeAttributesNamed(String... names)
-
removeAttributes
public void removeAttributes()
Remove all attributes of this element.
-
changeAttributeValue
public void changeAttributeValue(String name, UnaryOperator<String> modifier)
Changes the value of attributes that have a given name.- Parameters:
name- The attribute name.modifier- A function that take value and returns new value.
-
changeAttributeValue
public void changeAttributeValue(String name, UnaryOperator<String> modifier, boolean recurse)
Changes the value of attributes that have a given name.- Parameters:
name- The attribute name.modifier- A function that take value and returns new value.recurse- Iftrue, then this is applied recursively.
-
changeName
public void changeName(UnaryOperator<String> modifier)
Changes the element name.- Parameters:
modifier- A function that take name and returns new name.
-
changeName
public void changeName(UnaryOperator<String> modifier, boolean recurse)
Changes element names recursively.- Parameters:
modifier- A function that take name and returns new name.recurse- Iftrue, then this is applied recursively.
-
addText
public Text addText(String content, boolean merge)
Adds a text as last child.- Parameters:
content- The text content.merge- Iftrue, then if last child exists and is a text,contentis added to this last child.
Otherwise, a text child is created and added to last position.- Returns:
- The modified or created text.
-
addText
public Text addText(String content)
Adds a text as last child.If last child exists and is a text,
contentis added to this last child.
Otherwise, a text child is created and added to last position.- Parameters:
content- The text content.- Returns:
- The modified or created text.
-
getText
public String getText(String def)
Returns the merged content of all children text nodes, if this node has no element children.This will work when this node has only text and comment children.
If it has element children, the default value is returned.- Parameters:
def- The default value.- Returns:
- The merged content of children texts (ignoring comments) or
def.
-
getText
public String getText()
Returns the merged content of all children text nodes, if this node has no element children.This will work when this node has only text and comment children.
If it has element children,nullis returned.- Returns:
- The merged content of children texts (ignoring comments) or
null.
-
getTextAsBoolean
public boolean getTextAsBoolean(boolean def)
-
getTextAsLong
public long getTextAsLong(long def)
-
getTextAsInt
public int getTextAsInt(int def)
-
getTextAsShort
public short getTextAsShort(short def)
-
getTextAsByte
public byte getTextAsByte(byte def)
-
getTextAsDouble
public double getTextAsDouble(double def)
-
getTextAsFloat
public float getTextAsFloat(float def)
-
getTextAsOptionalEnum
public <E extends Enum<E>> E getTextAsOptionalEnum(Class<E> enumClass, E def)
-
getElementNamedText
public String getElementNamedText(String name, String def)
Returns the text content of the first child element that has a given name.- Parameters:
name- The child name.def- The default value.- Returns:
- The text of the first child named
nameordef.
-
getElementNamedText
public String getElementNamedText(String name)
Returns the text content of the first child element that has a given name.- Parameters:
name- The child name.- Returns:
- The text of the first child named
nameornull.
-
toString
public String toString()
- Overrides:
toStringin classAbstractChild
-
named
public static Predicate<Node> named(String name)
Creates a Predicate that accepts Nodes that are element with a given name.- Parameters:
name- The name.- Returns:
- A new Predicate that accepts Nodes that are elements named
name.
-
named
public static Predicate<Node> named(Set<String> names)
Creates a Predicate that accepts Nodes that are element whose named belongs to a set.- Parameters:
names- The names.- Returns:
- A new Predicate that accepts Nodes that are elements whose name belongs to
names.
-
named
public static Predicate<Node> named(String... names)
Creates a Predicate that accepts Nodes that are element whose named belongs to an array.- Parameters:
names- The names.- Returns:
- A new Predicate that accepts Nodes that are elements whose name belongs to
names.
-
namedWithAttribute
public static Predicate<Node> namedWithAttribute(String name, String attributeName, String attributeValue)
Creates a Predicate that accepts Nodes that are elements with a given name and have an attribute with a given value.- Parameters:
name- The element name.attributeName- The attribute name.attributeValue- The attribute value.- Returns:
- A new Predicate that accepts Nodes that are elements named
namewith an attribute namedattributeNameand containingattributeValue.
-
hasAttribute
public static Predicate<Node> hasAttribute(String attributeName, String attributeValue)
Creates a Predicate that accepts Nodes that are elements that have an attribute with a given value.- Parameters:
attributeName- The attribute name.attributeValue- The attribute value.- Returns:
- A new Predicate that accepts Nodes that are elements that have
an attribute named
attributeNameand containingattributeValue.
-
-