Class NodeIterator
java.lang.Object
org.openhab.core.config.core.xml.util.NodeIterator
The
NodeIterator
is an Iterator
for nodes of an XML document.
This iterator offers a simple mechanism iterating through Node
* objects by considering the required or
optional occurrences of attributes, values or list of values.
- Author:
- Michael Grammling - Initial contribution
-
Constructor Summary
ConstructorDescriptionNodeIterator
(@Nullable List<?> nodes) Creates a new instance of this class with the specified argument. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Ensures that the end of the node has been reached.boolean
hasNext()
@Nullable Object
next()
@Nullable Object
Returns the next object if the specified name of the node fits to the next node, ornull
if the node does not exist.@Nullable String
nextAttribute
(String nodeName, String attributeName, boolean required) Returns the next attribute if the specified name of the node fits to the next node and the attribute with the specified name could be found, ornull
if the node or attribute does not exist.@Nullable List<@NonNull ?>
Returns the next list of values if the specified name of the node fits to the next node, ornull
if the node does not exist.@Nullable Object
Returns the next value if the specified name of the node fits to the next node, ornull
if the node does not exist.void
remove()
void
revert()
Reverts the lastnext()
call.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Iterator
forEachRemaining
-
Constructor Details
-
NodeIterator
Creates a new instance of this class with the specified argument.- Parameters:
nodes
- the list of nodes to be iterated through (could be null or empty)
-
-
Method Details
-
hasNext
public boolean hasNext() -
next
-
remove
public void remove() -
revert
public void revert() -
assertEndOfType
public void assertEndOfType() throws com.thoughtworks.xstream.converters.ConversionExceptionEnsures that the end of the node has been reached.- Throws:
com.thoughtworks.xstream.converters.ConversionException
- if the end of the node has not reached yet
-
next
public @Nullable Object next(String nodeName, boolean required) throws com.thoughtworks.xstream.converters.ConversionException Returns the next object if the specified name of the node fits to the next node, ornull
if the node does not exist. In the last case the iterator will not increase its iteration counter.- Parameters:
nodeName
- the name of the node to be read next (must neither be null, nor empty)required
- true if the occurrence of the node has to be ensured- Returns:
- the next object if the specified name of the node fits to the next node, otherwise null
- Throws:
com.thoughtworks.xstream.converters.ConversionException
- if the specified node could not be found in the next node however it was specified as required
-
nextAttribute
public @Nullable String nextAttribute(String nodeName, String attributeName, boolean required) throws com.thoughtworks.xstream.converters.ConversionException Returns the next attribute if the specified name of the node fits to the next node and the attribute with the specified name could be found, ornull
if the node or attribute does not exist. In the last case the iterator will not increase its iteration counter.The next node must be of the type
NodeAttributes
.- Parameters:
nodeName
- the name of the node to be read next (must neither be null, nor empty)attributeName
- the name of the attribute of the node to be read next (must neither be null, nor empty)required
- true if the occurrence of the node's attribute has to be ensured- Returns:
- the next attribute of the specified name of the node and attribute (could be null or empty)
- Throws:
com.thoughtworks.xstream.converters.ConversionException
- if the specified node's attribute could not be found in the next node however it was specified as required
-
nextValue
public @Nullable Object nextValue(String nodeName, boolean required) throws com.thoughtworks.xstream.converters.ConversionException Returns the next value if the specified name of the node fits to the next node, ornull
if the node does not exist. In the last case the iterator will not increase its iteration counter.The next node must be of the type
NodeValue
.- Parameters:
nodeName
- the name of the node to be read next (must neither be null, nor empty)required
- true if the occurrence of the node's value has to be ensured- Returns:
- the next value of the specified name of the node (could be null or empty)
- Throws:
com.thoughtworks.xstream.converters.ConversionException
- if the specified node's value could not be found in the next node however it was specified as required
-
nextList
public @Nullable List<@NonNull ?> nextList(String nodeName, boolean required) throws com.thoughtworks.xstream.converters.ConversionException Returns the next list of values if the specified name of the node fits to the next node, ornull
if the node does not exist. In the last case the iterator will not increase its iteration counter.The next node must be of the type
NodeList
.- Parameters:
nodeName
- the name of the node to be read next (must neither be null, nor empty)required
- true if the occurrence of the node's list of values has to be ensured- Returns:
- the next list of values of the specified name of the node (could be null or empty)
- Throws:
com.thoughtworks.xstream.converters.ConversionException
- if the specified node's list of values could not be found in the next node however it was specified as required
-