java.lang.Object
net.luis.utils.io.data.xml.XmlAttributes
Represents a collection of xml attributes.
The class provides methods to query, add, remove, replace, and get attributes.
The class provides methods to query, add, remove, replace, and get attributes.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new empty xml attributes collection.XmlAttributes
(@NotNull Map<String, XmlAttribute> attributes) Constructs a new xml attributes collection with the given attributes.
The given attributes will be copied into the new collection. -
Method Summary
Modifier and TypeMethodDescription@Nullable XmlAttribute
Adds a new attribute with the given name and boolean value to this collection.@Nullable XmlAttribute
Adds a new attribute with the given name and byte value to this collection.@Nullable XmlAttribute
Adds a new attribute with the given name and double value to this collection.@Nullable XmlAttribute
Adds a new attribute with the given name and float value to this collection.@Nullable XmlAttribute
Adds a new attribute with the given name and integer value to this collection.@Nullable XmlAttribute
Adds a new attribute with the given name and long value to this collection.@Nullable XmlAttribute
Adds a new attribute with the given name and short value to this collection.@Nullable XmlAttribute
Adds a new attribute with the given name and number value to this collection.@Nullable XmlAttribute
Adds a new attribute with the given name and string value to this collection.@Nullable XmlAttribute
add
(@NotNull XmlAttribute attribute) Adds the given attribute to this collection.@NotNull @Unmodifiable Collection
<XmlAttribute> Returns an unmodifiable collection of all attributes in this collection.void
clear()
Removes all attributes from this collection.boolean
containsName
(@Nullable String name) Checks if this collection contains an attribute with the given name.boolean
containsValue
(@Nullable XmlAttribute attribute) Checks if this collection contains the given attribute.boolean
@Nullable XmlAttribute
Returns the attribute with the given name from this collection.<T> T
getAs
(@NotNull String name, @NotNull ThrowableFunction<String, T, ? extends Exception> parser) Returns the value of the attribute with the given name as the type of the given parser.boolean
getAsBoolean
(@NotNull String name) Returns the value of the attribute with the given name as a boolean.byte
Returns the value of the attribute with the given name as a byte.double
getAsDouble
(@NotNull String name) Returns the value of the attribute with the given name as a double.float
getAsFloat
(@NotNull String name) Returns the value of the attribute with the given name as a float.int
getAsInteger
(@NotNull String name) Returns the value of the attribute with the given name as an integer.long
Returns the value of the attribute with the given name as a long.@NotNull Number
getAsNumber
(@NotNull String name) Returns the value of the attribute with the given name as a number.short
getAsShort
(@NotNull String name) Returns the value of the attribute with the given name as a short.@NotNull String
getAsString
(@NotNull String name) Returns the value of the attribute with the given name as a string.int
hashCode()
boolean
isEmpty()
Checks if this collection contains no attributes.nameSet()
Returns an unmodifiable set of all attribute names in this collection.@Nullable XmlAttribute
Removes the attribute with the given name from this collection.@Nullable XmlAttribute
remove
(@NotNull XmlAttribute attribute) Removes the given attribute from this collection.@Nullable XmlAttribute
replace
(@NotNull String name, @NotNull XmlAttribute newAttribute) Replaces the attribute with the given name in this collection with the new attribute.boolean
replace
(@NotNull String name, @Nullable XmlAttribute currentAttribute, @NotNull XmlAttribute newAttribute) Replaces the attribute with the given name in this collection with the new attribute.
Under the condition that the name is associated with the given current attribute.int
size()
Returns the number of attributes in this collection.toString()
@NotNull String
Returns a string representation of this collection.
-
Field Details
-
attributes
The map of attributes.
-
-
Constructor Details
-
XmlAttributes
public XmlAttributes()Constructs a new empty xml attributes collection. -
XmlAttributes
Constructs a new xml attributes collection with the given attributes.
The given attributes will be copied into the new collection.- Parameters:
attributes
- The attributes- Throws:
NullPointerException
- If the given attributes are null
-
-
Method Details
-
size
public int size()Returns the number of attributes in this collection.- Returns:
- The size of this collection
-
isEmpty
public boolean isEmpty()Checks if this collection contains no attributes.- Returns:
- True if this collection contains no attributes, otherwise false
-
containsName
Checks if this collection contains an attribute with the given name.- Parameters:
name
- The name to check- Returns:
- True if this collection contains an attribute with the given name, otherwise false
-
containsValue
Checks if this collection contains the given attribute.- Parameters:
attribute
- The attribute to check- Returns:
- True if this collection contains the given attribute, otherwise false
-
nameSet
Returns an unmodifiable set of all attribute names in this collection.- Returns:
- The set of attribute names
-
attributes
Returns an unmodifiable collection of all attributes in this collection.- Returns:
- The collection of attributes
-
add
Adds the given attribute to this collection.- Parameters:
attribute
- The attribute to add- Returns:
- The previous attribute with the same name, or null if there was none
- Throws:
NullPointerException
- If the given attribute is null
-
add
@Nullable public @Nullable XmlAttribute add(@NotNull @NotNull String name, @Nullable @Nullable String value) Adds a new attribute with the given name and string value to this collection.- Parameters:
name
- The name of the attributevalue
- The string value of the attribute- Returns:
- The previous attribute with the same name, or null if there was none
- Throws:
NullPointerException
- If the given name is null- See Also:
-
add
Adds a new attribute with the given name and boolean value to this collection.- Parameters:
name
- The name of the attributevalue
- The boolean value of the attribute- Returns:
- The previous attribute with the same name, or null if there was none
- Throws:
NullPointerException
- If the given name is null- See Also:
-
add
@Nullable public @Nullable XmlAttribute add(@NotNull @NotNull String name, @Nullable @Nullable Number value) Adds a new attribute with the given name and number value to this collection.- Parameters:
name
- The name of the attributevalue
- The number value of the attribute- Returns:
- The previous attribute with the same name, or null if there was none
- Throws:
NullPointerException
- If the given name is null- See Also:
-
add
Adds a new attribute with the given name and byte value to this collection.- Parameters:
name
- The name of the attributevalue
- The byte value of the attribute- Returns:
- The previous attribute with the same name, or null if there was none
- Throws:
NullPointerException
- If the given name is null- See Also:
-
add
Adds a new attribute with the given name and short value to this collection.- Parameters:
name
- The name of the attributevalue
- The short value of the attribute- Returns:
- The previous attribute with the same name, or null if there was none
- Throws:
NullPointerException
- If the given name is null- See Also:
-
add
Adds a new attribute with the given name and integer value to this collection.- Parameters:
name
- The name of the attributevalue
- The integer value of the attribute- Returns:
- The previous attribute with the same name, or null if there was none
- Throws:
NullPointerException
- If the given name is null- See Also:
-
add
Adds a new attribute with the given name and long value to this collection.- Parameters:
name
- The name of the attributevalue
- The long value of the attribute- Returns:
- The previous attribute with the same name, or null if there was none
- Throws:
NullPointerException
- If the given name is null- See Also:
-
add
Adds a new attribute with the given name and float value to this collection.- Parameters:
name
- The name of the attributevalue
- The float value of the attribute- Returns:
- The previous attribute with the same name, or null if there was none
- Throws:
NullPointerException
- If the given name is null- See Also:
-
add
Adds a new attribute with the given name and double value to this collection.- Parameters:
name
- The name of the attributevalue
- The double value of the attribute- Returns:
- The previous attribute with the same name, or null if there was none
- Throws:
NullPointerException
- If the given name is null- See Also:
-
remove
Removes the attribute with the given name from this collection.- Parameters:
name
- The name of the attribute to remove- Returns:
- The removed attribute, or null if there was none
-
remove
Removes the given attribute from this collection.- Parameters:
attribute
- The attribute to remove- Returns:
- The removed attribute, or null if there was none
- Throws:
NullPointerException
- If the given attribute is null- See Also:
-
clear
public void clear()Removes all attributes from this collection. -
replace
@Nullable public @Nullable XmlAttribute replace(@NotNull @NotNull String name, @NotNull @NotNull XmlAttribute newAttribute) Replaces the attribute with the given name in this collection with the new attribute.- Parameters:
name
- The name of the attribute to replacenewAttribute
- The new attribute- Returns:
- The replaced attribute, or null if there was none
- Throws:
NullPointerException
- If the given name or new attribute is null
-
replace
public boolean replace(@NotNull @NotNull String name, @Nullable @Nullable XmlAttribute currentAttribute, @NotNull @NotNull XmlAttribute newAttribute) Replaces the attribute with the given name in this collection with the new attribute.
Under the condition that the name is associated with the given current attribute.- Parameters:
name
- The name of the attribute to replacecurrentAttribute
- The current attributenewAttribute
- The new attribute- Returns:
- True if the replacement was successful, otherwise false
- Throws:
NullPointerException
- If the given name or new attribute is null
-
get
Returns the attribute with the given name from this collection.- Parameters:
name
- The name of the attribute to get- Returns:
- The attribute, or null if there was none
- Throws:
NullPointerException
- If the given name is null
-
getAsString
Returns the value of the attribute with the given name as a string.- Parameters:
name
- The name of the attribute to get- Returns:
- The value as a string
- Throws:
NullPointerException
- If the given name is nullNoSuchXmlAttributeException
- If there is no attribute with the given name
-
getAsBoolean
Returns the value of the attribute with the given name as a boolean.- Parameters:
name
- The name of the attribute to get- Returns:
- The value as a boolean
- Throws:
NullPointerException
- If the given name is nullNoSuchXmlAttributeException
- If there is no attribute with the given name
-
getAsNumber
Returns the value of the attribute with the given name as a number.- Parameters:
name
- The name of the attribute to get- Returns:
- The value as a number
- Throws:
NullPointerException
- If the given name is nullNoSuchXmlAttributeException
- If there is no attribute with the given name
-
getAsByte
Returns the value of the attribute with the given name as a byte.- Parameters:
name
- The name of the attribute to get- Returns:
- The value as a byte
- Throws:
NullPointerException
- If the given name is nullNoSuchXmlAttributeException
- If there is no attribute with the given name
-
getAsShort
Returns the value of the attribute with the given name as a short.- Parameters:
name
- The name of the attribute to get- Returns:
- The value as a short
- Throws:
NullPointerException
- If the given name is nullNoSuchXmlAttributeException
- If there is no attribute with the given name
-
getAsInteger
Returns the value of the attribute with the given name as an integer.- Parameters:
name
- The name of the attribute to get- Returns:
- The value as an integer
- Throws:
NullPointerException
- If the given name is nullNoSuchXmlAttributeException
- If there is no attribute with the given name
-
getAsLong
Returns the value of the attribute with the given name as a long.- Parameters:
name
- The name of the attribute to get- Returns:
- The value as a long
- Throws:
NullPointerException
- If the given name is nullNoSuchXmlAttributeException
- If there is no attribute with the given name
-
getAsFloat
Returns the value of the attribute with the given name as a float.- Parameters:
name
- The name of the attribute to get- Returns:
- The value as a float
- Throws:
NullPointerException
- If the given name is nullNoSuchXmlAttributeException
- If there is no attribute with the given name
-
getAsDouble
Returns the value of the attribute with the given name as a double.- Parameters:
name
- The name of the attribute to get- Returns:
- The value as a double
- Throws:
NullPointerException
- If the given name is nullNoSuchXmlAttributeException
- If there is no attribute with the given name
-
getAs
@NotNull public <T> T getAs(@NotNull @NotNull String name, @NotNull @NotNull ThrowableFunction<String, T, ? extends Exception> parser) Returns the value of the attribute with the given name as the type of the given parser.- Type Parameters:
T
- The type to convert the value to- Parameters:
name
- The name of the attribute to getparser
- The parser to convert the value to the given type- Returns:
- The value as the given type
- Throws:
NullPointerException
- If the given name or parser is nullNoSuchXmlAttributeException
- If there is no attribute with the given name
-
equals
-
hashCode
public int hashCode() -
toString
-
toString
Returns a string representation of this collection.- Parameters:
config
- The xml config to use- Returns:
- The string representation
-