java.lang.Object
net.luis.utils.io.data.xml.XmlElements
Represents a collection of xml elements.
The class provides methods to query, add, remove, and get elements.
 
The class provides methods to query, add, remove, and get elements.
     The collection can be either an object or an array.
     If the collection has exactly one element, it's undefined whether it's an object or an array.
     In this case, the next element which is added will determine the type of the collection.
 
     In the case this is an object collection, the keys of the elements must be unique.
     If an element with a key that already exists is added, an exception will be thrown.
 
     In the case this is an array collection, the keys of the elements must be the same.
     If an element with a key that is different from the existing elements is added, an exception will be thrown.
 
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprivate final SequencedMap<String, List<XmlElement>> The elements of the collection.
- 
Constructor SummaryConstructorsConstructorDescriptionConstructs a new, empty xml elements collection.XmlElements(@NotNull List<? extends XmlElement> elements) Constructs a new xml elements collection with the given elements.
 This constructor will determine the type of the collection based on the elements.XmlElements(@NotNull Map<String, ? extends XmlElement> elements) Constructs a new xml elements collection with the given elements.
 This constructor will determine the type of the collection based on the elements.
- 
Method SummaryModifier and TypeMethodDescriptionvoidadd(@NotNull XmlElement element) Adds the given element to the collection.voidaddContainer(@NotNull XmlContainer container) Adds the given container to the collection.voidAdds the given value to the collection.voidclear()Removes all elements from the collection.booleancontainsElement(@Nullable XmlElement element) Checks if this collection contains the given element considering the type.booleancontainsName(@Nullable String name) Checks if this collection contains an element with the given name.@NotNull @Unmodifiable Collection<XmlElement> elements()Returns an unmodifiable collection of all elements in the collection considering the type.boolean@Nullable XmlElementget(int index) Returns the element with the given index from the collection.
 This method should only be used if the collection is an array.@Nullable XmlElementReturns the element with the given name from the collection.
 This method should only be used if the collection is an object.@NotNull @Unmodifiable List<XmlElement> Returns the elements of the collection as an unmodifiable list.
 This method should only be used if the collection is an array.@NotNull XmlContainergetAsContainer(int index) Returns the element with the given index from the collection as a container.
 This method should only be used if the collection is an array.@NotNull XmlContainergetAsContainer(@Nullable String name) Returns the element with the given name from the collection as a container.
 This method should only be used if the collection is an object.@NotNull @Unmodifiable Map<String, XmlElement> Returns the elements of the collection as an unmodifiable map.
 This method should only be used if the collection is an object.@NotNull XmlValuegetAsValue(int index) Returns the element with the given index from the collection as a value.
 This method should only be used if the collection is an array.@NotNull XmlValuegetAsValue(@Nullable String name) Returns the element with the given name from the collection as a value.
 This method should only be used if the collection is an object.inthashCode()booleanisArray()Checks whether the collection is an array.
 An array is a collection with exactly one key and multiple elements.booleanisEmpty()Checks if this collection contains no elements.booleanisObject()Checks whether the collection is an object.
 An object is a collection with multiple keys.
 Each key has exactly one element.booleanChecks whether the collection is undefined.nameSet()Returns an unmodifiable set of all element names in the collection.booleanremove(int index) Removes the element with the given index from the collection.
 This method should only be used if the collection is an array.booleanRemoves the element with the given name from the collection.
 This method should only be used if the collection is an object.booleanremove(@NotNull XmlElement element) Removes the given element from the collection considering the type.intsize()Returns the number of elements in the collection considering the type.toString()@NotNull StringReturns a string representation of the collection using the given xml config.
- 
Field Details- 
elementsThe elements of the collection.
 
- 
- 
Constructor Details- 
XmlElementspublic XmlElements()Constructs a new, empty xml elements collection.
- 
XmlElementsConstructs a new xml elements collection with the given elements.
 This constructor will determine the type of the collection based on the elements.- Parameters:
- elements- The elements to add to the collection
- Throws:
- NullPointerException- If the elements are null
- XmlTypeException- If the elements are not valid for the collection type
 
- 
XmlElementsConstructs a new xml elements collection with the given elements.
 This constructor will determine the type of the collection based on the elements.- Parameters:
- elements- The elements to add to the collection
- Throws:
- NullPointerException- If the elements are null
- XmlTypeException- If the elements are not valid for the collection type
 
 
- 
- 
Method Details- 
isUndefinedpublic boolean isUndefined()Checks whether the collection is undefined.- Returns:
- True if the collection is neither an object nor an array, false otherwise
 
- 
isArraypublic boolean isArray()Checks whether the collection is an array.
 An array is a collection with exactly one key and multiple elements.- Returns:
- True if the collection is an array, false otherwise
 
- 
isObjectpublic boolean isObject()Checks whether the collection is an object.
 An object is a collection with multiple keys.
 Each key has exactly one element.- Returns:
- True if the collection is an object, false otherwise
 
- 
sizepublic int size()Returns the number of elements in the collection considering the type.- Returns:
- The size of the collection
 
- 
isEmptypublic boolean isEmpty()Checks if this collection contains no elements.- Returns:
- True if the collection is empty, false otherwise
 
- 
containsNameChecks if this collection contains an element with the given name.- Parameters:
- name- The name of the element to check for
- Returns:
- True if the collection contains an element with the given name, false otherwise
 
- 
containsElementChecks if this collection contains the given element considering the type.- Parameters:
- element- The element to check for
- Returns:
- True if the collection contains the given element, false otherwise
 
- 
nameSetReturns an unmodifiable set of all element names in the collection.- Returns:
- The set of element names
 
- 
elementsReturns an unmodifiable collection of all elements in the collection considering the type.- Returns:
- The collection of elements
 
- 
addAdds the given element to the collection.- Parameters:
- element- The element to add
- Throws:
- NullPointerException- If the element is null
- XmlTypeException- If the element is not valid for the collection type
 
- 
addContainerAdds the given container to the collection.- Parameters:
- container- The container to add
- Throws:
- NullPointerException- If the container is null
- XmlTypeException- If the container is not valid for the collection type
 
- 
addValueAdds the given value to the collection.- Parameters:
- value- The value to add
- Throws:
- NullPointerException- If the value is null
- XmlTypeException- If the value is not valid for the collection type
 
- 
removeRemoves the given element from the collection considering the type.- Parameters:
- element- The element to remove
- Returns:
- True if the element was removed, false otherwise
- Throws:
- NullPointerException- If the element is null
 
- 
removeRemoves the element with the given name from the collection.
 This method should only be used if the collection is an object.- Parameters:
- name- The name of the element to remove
- Returns:
- True if an element was removed, false otherwise
- Throws:
- XmlTypeException- If the collection is an array
 
- 
removepublic boolean remove(int index) Removes the element with the given index from the collection.
 This method should only be used if the collection is an array.- Parameters:
- index- The index of the element to remove
- Returns:
- True if an element was removed, false otherwise
- Throws:
- XmlTypeException- If the collection is an object
 
- 
clearpublic void clear()Removes all elements from the collection.
- 
getReturns the element with the given name from the collection.
 This method should only be used if the collection is an object.- Parameters:
- name- The name of the element to get
- Returns:
- The element with the given name or null if no element with the name exists
- Throws:
- XmlTypeException- If the collection is an array
- See Also:
 
- 
getAsContainerReturns the element with the given name from the collection as a container.
 This method should only be used if the collection is an object.- Parameters:
- name- The name of the element to get
- Returns:
- The element with the given name as a container
- Throws:
- XmlTypeException- If the collection is an array or the element is not a container
- NoSuchXmlElementException- If no element with the given name exists
- See Also:
 
- 
getAsValueReturns the element with the given name from the collection as a value.
 This method should only be used if the collection is an object.- Parameters:
- name- The name of the element to get
- Returns:
- The element with the given name as a value
- Throws:
- XmlTypeException- If the collection is an array or the element is not a value
- NoSuchXmlElementException- If no element with the given name exists
- See Also:
 
- 
getReturns the element with the given index from the collection.
 This method should only be used if the collection is an array.- Parameters:
- index- The index of the element to get
- Returns:
- The element with the given index or null if no element with the index exists
- Throws:
- XmlTypeException- If the collection is an object
 
- 
getAsContainerReturns the element with the given index from the collection as a container.
 This method should only be used if the collection is an array.- Parameters:
- index- The index of the element to get
- Returns:
- The element with the given index as a container
- Throws:
- XmlTypeException- If the collection is an object
- NoSuchXmlElementException- If no element with the given index exists
- See Also:
 
- 
getAsValueReturns the element with the given index from the collection as a value.
 This method should only be used if the collection is an array.- Parameters:
- index- The index of the element to get
- Returns:
- The element with the given index as a value
- Throws:
- XmlTypeException- If the collection is an object
- NoSuchXmlElementException- If no element with the given index exists
- See Also:
 
- 
getAsArrayReturns the elements of the collection as an unmodifiable list.
 This method should only be used if the collection is an array.- Returns:
- The elements of the collection
- Throws:
- XmlTypeException- If the collection is an object
 
- 
getAsObjectReturns the elements of the collection as an unmodifiable map.
 This method should only be used if the collection is an object.- Returns:
- The elements of the collection
- Throws:
- XmlTypeException- If the collection is an array
 
- 
equals
- 
hashCodepublic int hashCode()
- 
toString
- 
toStringReturns a string representation of the collection using the given xml config.- Parameters:
- config- The xml config to use
- Returns:
- The string representation of the collection
- Throws:
- NullPointerException- If the xml config is null
 
 
-