java.lang.Object
net.luis.utils.io.data.xml.XmlElement
- Direct Known Subclasses:
XmlContainer,XmlValue
Represents a xml element.
A xml element can be a self-closing element, a container element or a value element.
A xml element can be a self-closing element, a container element or a value element.
A self-closing element is an element that does not have any content.
It is represented by a tag with a name and optional attributes.
A container element is an element that contains other elements.
It is represented by a tag with a name, optional attributes and a closing tag.
The containing elements have either all the same name or unique names.
A value element is an element that contains a value.
It is represented by a tag with a name, optional attributes and a value.
The value can be a string, a number or a boolean.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final XmlAttributesThe attributes of the xml element.private final StringThe name of the xml element. -
Constructor Summary
ConstructorsConstructorDescriptionXmlElement(@NotNull String name) Constructs a new xml element with the specified name and no attributes.XmlElement(@NotNull String name, @NotNull XmlAttributes attributes) Constructs a new xml element with the specified name and attributes. -
Method Summary
Modifier and TypeMethodDescription@Nullable XmlAttributeaddAttribute(@NotNull String key, boolean value) Adds a new attribute with the given name and boolean value to this element.@Nullable XmlAttributeaddAttribute(@NotNull String key, byte value) Adds a new attribute with the given name and byte value to this element.@Nullable XmlAttributeaddAttribute(@NotNull String key, double value) Adds a new attribute with the given name and double value to this element.@Nullable XmlAttributeaddAttribute(@NotNull String key, float value) Adds a new attribute with the given name and float value to this element.@Nullable XmlAttributeaddAttribute(@NotNull String key, int value) Adds a new attribute with the given name and integer value to this element.@Nullable XmlAttributeaddAttribute(@NotNull String key, long value) Adds a new attribute with the given name and long value to this element.@Nullable XmlAttributeaddAttribute(@NotNull String key, short value) Adds a new attribute with the given name and short value to this element.@Nullable XmlAttributeaddAttribute(@NotNull String key, @Nullable Number value) Adds a new attribute with the given name and number value to this element.@Nullable XmlAttributeaddAttribute(@NotNull String key, @Nullable String value) Adds a new attribute with the given name and string value to this element.@Nullable XmlAttributeaddAttribute(@NotNull XmlAttribute attribute) Adds the specified attribute to the element.boolean@NotNull XmlContainerConverts this xml element to a xml container.@NotNull XmlValueConverts this xml element to a xml value.@Nullable XmlAttributegetAttribute(@NotNull String key) Returns the attribute with the specified key, or null if there is no such attribute in this element.<T> TgetAttributeAs(@NotNull String key, @NotNull ThrowableFunction<String, T, ? extends Exception> parser) Returns the attribute with the specified key as the type specified by the parser.booleangetAttributeAsBoolean(@NotNull String key) Returns the attribute with the specified key as a boolean.bytegetAttributeAsByte(@NotNull String key) Returns the attribute with the specified key as a byte.doublegetAttributeAsDouble(@NotNull String key) Returns the attribute with the specified key as a double.floatgetAttributeAsFloat(@NotNull String key) Returns the attribute with the specified key as a float.intgetAttributeAsInteger(@NotNull String key) Returns the attribute with the specified key as an integer.longgetAttributeAsLong(@NotNull String key) Returns the attribute with the specified key as a long.@NotNull NumbergetAttributeAsNumber(@NotNull String key) Returns the attribute with the specified key as a number.shortgetAttributeAsShort(@NotNull String key) Returns the attribute with the specified key as a short.@NotNull StringgetAttributeAsString(@NotNull String key) Returns the attribute with the specified key as a string.@NotNull XmlAttributesReturns the attributes of the xml element.protected @NotNull StringReturns the type of the xml element.
This is used internally for error messages.@NotNull StringgetName()Returns the name of the xml element.inthashCode()booleanChecks if the xml element is self-closing.booleanChecks if the xml element is a container.booleanChecks if the xml element is a value.protected @NotNull StringBuildertoBaseString(@NotNull XmlConfig config) Returns a string builder with the base string representation of this xml element.
The base string representation contains the root tag with the name and attributes.toString()@NotNull StringThe string representation of this xml element.
-
Field Details
-
name
The name of the xml element. -
attributes
The attributes of the xml element.
-
-
Constructor Details
-
XmlElement
Constructs a new xml element with the specified name and no attributes.- Parameters:
name- The name of the xml element- Throws:
NullPointerException- If the name is nullIllegalArgumentException- If the name is invalid
-
XmlElement
Constructs a new xml element with the specified name and attributes.- Parameters:
name- The name of the xml elementattributes- The attributes of the xml element- Throws:
NullPointerException- If the name or attributes are nullIllegalArgumentException- If the name is invalid
-
-
Method Details
-
getElementType
Returns the type of the xml element.
This is used internally for error messages.- Returns:
- The type of the xml element
-
isSelfClosing
public boolean isSelfClosing()Checks if the xml element is self-closing.- Returns:
- Always true
-
isXmlContainer
public boolean isXmlContainer()Checks if the xml element is a container.- Returns:
- True if the xml element is a container, false otherwise
-
isXmlValue
public boolean isXmlValue()Checks if the xml element is a value.- Returns:
- True if the xml element is a value, false otherwise
-
getAsXmlContainer
Converts this xml element to a xml container.- Returns:
- This xml element as a xml container
- Throws:
XmlTypeException- If this xml element is not a xml container
-
getAsXmlValue
Converts this xml element to a xml value.- Returns:
- This xml element as a xml value
- Throws:
XmlTypeException- If this xml element is not a xml value
-
getName
Returns the name of the xml element.- Returns:
- The element name
-
getAttributes
Returns the attributes of the xml element.- Returns:
- The element attributes (modifiable)
-
addAttribute
Adds the specified attribute to the element.- Parameters:
attribute- The attribute to add- Returns:
- The previous attribute with the same key, or null if there was no previous attribute
- See Also:
-
addAttribute
@Nullable public @Nullable XmlAttribute addAttribute(@NotNull @NotNull String key, @Nullable @Nullable String value) Adds a new attribute with the given name and string value to this element.- Parameters:
key- The key of the attributevalue- The value of the attribute- Returns:
- The previous attribute with the same key, or null if there was no previous attribute
- See Also:
-
addAttribute
Adds a new attribute with the given name and boolean value to this element.- Parameters:
key- The key of the attributevalue- The value of the attribute- Returns:
- The previous attribute with the same key, or null if there was no previous attribute
- See Also:
-
addAttribute
@Nullable public @Nullable XmlAttribute addAttribute(@NotNull @NotNull String key, @Nullable @Nullable Number value) Adds a new attribute with the given name and number value to this element.- Parameters:
key- The key of the attributevalue- The value of the attribute- Returns:
- The previous attribute with the same key, or null if there was no previous attribute
- See Also:
-
addAttribute
Adds a new attribute with the given name and byte value to this element.- Parameters:
key- The key of the attributevalue- The value of the attribute- Returns:
- The previous attribute with the same key, or null if there was no previous attribute
- See Also:
-
addAttribute
Adds a new attribute with the given name and short value to this element.- Parameters:
key- The key of the attributevalue- The value of the attribute- Returns:
- The previous attribute with the same key, or null if there was no previous attribute
- See Also:
-
addAttribute
Adds a new attribute with the given name and integer value to this element.- Parameters:
key- The key of the attributevalue- The value of the attribute- Returns:
- The previous attribute with the same key, or null if there was no previous attribute
- See Also:
-
addAttribute
Adds a new attribute with the given name and long value to this element.- Parameters:
key- The key of the attributevalue- The value of the attribute- Returns:
- The previous attribute with the same key, or null if there was no previous attribute
- See Also:
-
addAttribute
Adds a new attribute with the given name and float value to this element.- Parameters:
key- The key of the attributevalue- The value of the attribute- Returns:
- The previous attribute with the same key, or null if there was no previous attribute
- See Also:
-
addAttribute
Adds a new attribute with the given name and double value to this element.- Parameters:
key- The key of the attributevalue- The value of the attribute- Returns:
- The previous attribute with the same key, or null if there was no previous attribute
- See Also:
-
getAttribute
Returns the attribute with the specified key, or null if there is no such attribute in this element.- Parameters:
key- The key of the attribute- Returns:
- The attribute with the specified key, or null if there is no such attribute
- See Also:
-
getAttributeAsString
Returns the attribute with the specified key as a string.- Parameters:
key- The key of the attribute- Returns:
- The value of the attribute as a string
- See Also:
-
getAttributeAsBoolean
Returns the attribute with the specified key as a boolean.- Parameters:
key- The key of the attribute- Returns:
- The value of the attribute as a boolean
- See Also:
-
getAttributeAsNumber
Returns the attribute with the specified key as a number.- Parameters:
key- The key of the attribute- Returns:
- The value of the attribute as a number
- See Also:
-
getAttributeAsByte
Returns the attribute with the specified key as a byte.- Parameters:
key- The key of the attribute- Returns:
- The value of the attribute as a byte
- See Also:
-
getAttributeAsShort
Returns the attribute with the specified key as a short.- Parameters:
key- The key of the attribute- Returns:
- The value of the attribute as a short
- See Also:
-
getAttributeAsInteger
Returns the attribute with the specified key as an integer.- Parameters:
key- The key of the attribute- Returns:
- The value of the attribute as an integer
- See Also:
-
getAttributeAsLong
Returns the attribute with the specified key as a long.- Parameters:
key- The key of the attribute- Returns:
- The value of the attribute as a long
- See Also:
-
getAttributeAsFloat
Returns the attribute with the specified key as a float.- Parameters:
key- The key of the attribute- Returns:
- The value of the attribute as a float
- See Also:
-
getAttributeAsDouble
Returns the attribute with the specified key as a double.- Parameters:
key- The key of the attribute- Returns:
- The value of the attribute as a double
- See Also:
-
getAttributeAs
@NotNull public <T> T getAttributeAs(@NotNull @NotNull String key, @NotNull @NotNull ThrowableFunction<String, T, ? extends Exception> parser) Returns the attribute with the specified key as the type specified by the parser.- Type Parameters:
T- The type of the value- Parameters:
key- The key of the attributeparser- The parser to convert the attribute value to the desired type- Returns:
- The value of the attribute as the specified type
- See Also:
-
equals
-
hashCode
public int hashCode() -
toString
-
toBaseString
Returns a string builder with the base string representation of this xml element.
The base string representation contains the root tag with the name and attributes.- Parameters:
config- The xml config to use for the string representation- Returns:
- The string builder
- Throws:
NullPointerException- If the xml config is nullIllegalStateException- If the element cannot be represented as a string because of the xml config
-
toString
The string representation of this xml element.- Parameters:
config- The xml config to use for the string representation- Returns:
- The string representation
- Throws:
NullPointerException- If the xml config is null
-