java.lang.Object
net.luis.utils.io.data.xml.XmlElement
net.luis.utils.io.data.xml.XmlContainer
Represents an xml container element.
A container element can contain other elements.
A container element can contain other elements.
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionXmlContainer
(@NotNull String name) Constructs a new xml container with the given name.XmlContainer
(@NotNull String name, @NotNull XmlAttributes attributes) Constructs a new xml container with the given name and attributes.XmlContainer
(@NotNull String name, @NotNull XmlAttributes attributes, @NotNull XmlElements elements) Constructs a new xml container with the given name, attributes and elements.XmlContainer
(@NotNull String name, @NotNull XmlElements elements) Constructs a new xml container with the given name and elements. -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(@NotNull XmlElement element) Adds the given element to this container.void
addContainer
(@NotNull XmlContainer container) Adds the given container to this container.void
Adds the given value to this container.void
clear()
Removes all elements from this container.boolean
containsElement
(@Nullable XmlElement element) Checks if this container contains the given element.boolean
containsName
(@Nullable String name) Checks if this container contains an element with the given name.@NotNull @Unmodifiable Collection
<XmlElement> elements()
Returns an unmodifiable collection of the elements in this container.boolean
@Nullable XmlElement
get
(int index) Returns the element at the given index from this container.
This method should only be used if the container is an array.@Nullable XmlElement
Returns the element with the given name from this container.
This method should only be used if the container is an object.@NotNull XmlContainer
getAsContainer
(int index) Returns the element at the given index from this container.
This method should only be used if the container is an array.@NotNull XmlContainer
getAsContainer
(@Nullable String name) Returns the element with the given name from this container.
This method should only be used if the container is an object.@NotNull XmlValue
getAsValue
(int index) Returns the element at the given index from this container.
This method should only be used if the container is an array.@NotNull XmlValue
getAsValue
(@Nullable String name) Returns the element with the given name from this container.
This method should only be used if the container is an object.@NotNull XmlElements
Returns the elements of this container.protected @NotNull String
Returns the type of the xml element.
This is used internally for error messages.int
hashCode()
boolean
Checks if the collection of elements in this container is an array.boolean
Checks if the collection of elements in this container is an object.boolean
isEmpty()
Checks if this container contains no elements.boolean
Checks if the xml element is self-closing.boolean
Checks if the collection of elements in this container is undefined.nameSet()
Returns an unmodifiable set of the names of the elements in this container.boolean
remove
(int index) Removes the element with the given index from this container.
This method should only be used if the collection is an array.boolean
Removes the element with the given name from this container.
This method should only be used if the collection is an object.boolean
remove
(@NotNull XmlElement element) Removes the given element from this container.int
size()
Returns the number of elements in this container.@NotNull String
Returns a string representation of this container.Methods inherited from class net.luis.utils.io.data.xml.XmlElement
addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, addAttribute, getAsXmlContainer, getAsXmlValue, getAttribute, getAttributeAs, getAttributeAsBoolean, getAttributeAsByte, getAttributeAsDouble, getAttributeAsFloat, getAttributeAsInteger, getAttributeAsLong, getAttributeAsNumber, getAttributeAsShort, getAttributeAsString, getAttributes, getName, isXmlContainer, isXmlValue, toBaseString, toString
-
Field Details
-
elements
The elements of this container.
-
-
Constructor Details
-
XmlContainer
Constructs a new xml container with the given name.- Parameters:
name
- The name of the container- Throws:
NullPointerException
- If the name is null
-
XmlContainer
Constructs a new xml container with the given name and elements.- Parameters:
name
- The name of the containerelements
- The elements of the container- Throws:
NullPointerException
- If the name or elements are null
-
XmlContainer
Constructs a new xml container with the given name and attributes.- Parameters:
name
- The name of the containerattributes
- The attributes of the container- Throws:
NullPointerException
- If the name or attributes are null
-
XmlContainer
public XmlContainer(@NotNull @NotNull String name, @NotNull @NotNull XmlAttributes attributes, @NotNull @NotNull XmlElements elements) Constructs a new xml container with the given name, attributes and elements.- Parameters:
name
- The name of the containerattributes
- The attributes of the containerelements
- The elements of the container- Throws:
NullPointerException
- If the name, attributes or elements are null
-
-
Method Details
-
getElementType
Description copied from class:XmlElement
Returns the type of the xml element.
This is used internally for error messages.- Overrides:
getElementType
in classXmlElement
- Returns:
- The type of the xml element
-
isSelfClosing
public boolean isSelfClosing()Description copied from class:XmlElement
Checks if the xml element is self-closing.- Overrides:
isSelfClosing
in classXmlElement
- Returns:
- Always false
-
getElements
Returns the elements of this container.- Returns:
- The elements of this container (modifiable)
-
isUndefinedContainer
public boolean isUndefinedContainer()Checks if the collection of elements in this container is undefined.- Returns:
- True if the collection of elements is undefined, otherwise false
-
isContainerArray
public boolean isContainerArray()Checks if the collection of elements in this container is an array.- Returns:
- True if the collection of elements is an array, otherwise false
-
isContainerObject
public boolean isContainerObject()Checks if the collection of elements in this container is an object.- Returns:
- True if the collection of elements is an object, otherwise false
-
size
public int size()Returns the number of elements in this container.- Returns:
- The size of the container
-
isEmpty
public boolean isEmpty()Checks if this container contains no elements.- Returns:
- True if this container contains no elements, otherwise false
-
containsName
Checks if this container contains an element with the given name.- Parameters:
name
- The name of the element- Returns:
- True if this container contains an element with the given name, otherwise false
-
containsElement
Checks if this container contains the given element.- Parameters:
element
- The element to check- Returns:
- True if this container contains the given element, otherwise false
-
nameSet
Returns an unmodifiable set of the names of the elements in this container.- Returns:
- The set of names
-
elements
Returns an unmodifiable collection of the elements in this container.- Returns:
- The collection of elements
-
add
Adds the given element to this container.- Parameters:
element
- The element to add- Throws:
NullPointerException
- If the element is nullXmlTypeException
- If the element is not valid for the collection type
-
addContainer
Adds the given container to this container.- Parameters:
container
- The container to add- Throws:
NullPointerException
- If the container is nullXmlTypeException
- If the container is not valid for the collection type
-
addValue
Adds the given value to this container.- Parameters:
value
- The value to add- Throws:
NullPointerException
- If the value is nullXmlTypeException
- If the value is not valid for the collection type
-
remove
Removes the given element from this container.- Parameters:
element
- The element to remove- Returns:
- True if the element was removed, otherwise false
-
remove
Removes the element with the given name from this container.
This method should only be used if the collection is an object.- Parameters:
name
- The name of the element to remove- Returns:
- True if the element was removed, otherwise false
- Throws:
XmlTypeException
- If the collection is an array
-
remove
public boolean remove(int index) Removes the element with the given index from this container.
This method should only be used if the collection is an array.- Parameters:
index
- The name of the element to remove- Returns:
- True if the element was removed, otherwise false
- Throws:
XmlTypeException
- If the collection is an object
-
clear
public void clear()Removes all elements from this container. -
get
Returns the element with the given name from this container.
This method should only be used if the container is an object.- Parameters:
name
- The name of the element- Returns:
- The element with the given name, or null if the element does not exist
- Throws:
XmlTypeException
- If the container is not an array- See Also:
-
getAsContainer
Returns the element with the given name from this container.
This method should only be used if the container is an object.- Parameters:
name
- The name of the element- Returns:
- The element with the given name
- Throws:
XmlTypeException
- If the container is an arrayNoSuchXmlElementException
- If the element does not exist- See Also:
-
getAsValue
Returns the element with the given name from this container.
This method should only be used if the container is an object.- Parameters:
name
- The name of the element- Returns:
- The element with the given name
- Throws:
XmlTypeException
- If the container is an arrayNoSuchXmlElementException
- If the element does not exist- See Also:
-
get
Returns the element at the given index from this container.
This method should only be used if the container is an array.- Parameters:
index
- The index of the element- Returns:
- The element with the given index, or null if no element with the index exists
- Throws:
XmlTypeException
- If the container is not an array- See Also:
-
getAsContainer
Returns the element at the given index from this container.
This method should only be used if the container is an array.- Parameters:
index
- The index of the element- Returns:
- The element with the given index
- Throws:
XmlTypeException
- If the container is an objectNoSuchXmlElementException
- If no element with the given index exists- See Also:
-
getAsValue
Returns the element at the given index from this container.
This method should only be used if the container is an array.- Parameters:
index
- The index of the element- Returns:
- The element with the given index
- Throws:
XmlTypeException
- If the container is an objectNoSuchXmlElementException
- If no element with the given index exists- See Also:
-
equals
- Overrides:
equals
in classXmlElement
-
hashCode
public int hashCode()- Overrides:
hashCode
in classXmlElement
-
toString
Returns a string representation of this container.- Overrides:
toString
in classXmlElement
- Parameters:
config
- The xml config to use for the string representation- Returns:
- The string representation
- Throws:
NullPointerException
- If the config is null
-