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 TypeMethodDescriptionvoidadd(@NotNull XmlElement element) Adds the given element to this container.voidaddContainer(@NotNull XmlContainer container) Adds the given container to this container.voidAdds the given value to this container.voidclear()Removes all elements from this container.booleancontainsElement(@Nullable XmlElement element) Checks if this container contains the given element.booleancontainsName(@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 XmlElementget(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 XmlElementReturns the element with the given name from this container.
This method should only be used if the container is an object.@NotNull XmlContainergetAsContainer(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 XmlContainergetAsContainer(@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 XmlValuegetAsValue(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 XmlValuegetAsValue(@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 XmlElementsReturns the elements of this container.protected @NotNull StringReturns the type of the xml element.
This is used internally for error messages.inthashCode()booleanChecks if the collection of elements in this container is an array.booleanChecks if the collection of elements in this container is an object.booleanisEmpty()Checks if this container contains no elements.booleanChecks if the xml element is self-closing.booleanChecks if the collection of elements in this container is undefined.nameSet()Returns an unmodifiable set of the names of the elements in this container.booleanremove(int index) Removes the element with the given index from this container.
This method should only be used if the collection is an array.booleanRemoves the element with the given name from this container.
This method should only be used if the collection is an object.booleanremove(@NotNull XmlElement element) Removes the given element from this container.intsize()Returns the number of elements in this container.@NotNull StringReturns 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:XmlElementReturns the type of the xml element.
This is used internally for error messages.- Overrides:
getElementTypein classXmlElement- Returns:
- The type of the xml element
-
isSelfClosing
public boolean isSelfClosing()Description copied from class:XmlElementChecks if the xml element is self-closing.- Overrides:
isSelfClosingin 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:
equalsin classXmlElement
-
hashCode
public int hashCode()- Overrides:
hashCodein classXmlElement
-
toString
Returns a string representation of this container.- Overrides:
toStringin classXmlElement- Parameters:
config- The xml config to use for the string representation- Returns:
- The string representation
- Throws:
NullPointerException- If the config is null
-