Class NodeIterator

java.lang.Object
org.openhab.core.config.core.xml.util.NodeIterator
All Implemented Interfaces:
Iterator<@Nullable Object>

@NonNullByDefault public class NodeIterator extends Object implements Iterator<@Nullable Object>
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

    Constructors
    Constructor
    Description
    NodeIterator(@Nullable List<?> nodes)
    Creates a new instance of this class with the specified argument.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Ensures that the end of the node has been reached.
    boolean
     
    @Nullable Object
     
    @Nullable Object
    next(String nodeName, boolean required)
    Returns the next object if the specified name of the node fits to the next node, or null 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, or null if the node or attribute does not exist.
    @Nullable List<@NonNull ?>
    nextList(String nodeName, boolean required)
    Returns the next list of values if the specified name of the node fits to the next node, or null if the node does not exist.
    @Nullable Object
    nextValue(String nodeName, boolean required)
    Returns the next value if the specified name of the node fits to the next node, or null if the node does not exist.
    void
     
    void
    Reverts the last next() 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

      public NodeIterator(@Nullable List<?> nodes)
      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()
      Specified by:
      hasNext in interface Iterator<@Nullable Object>
    • next

      public @Nullable Object next()
      Specified by:
      next in interface Iterator<@Nullable Object>
    • remove

      public void remove()
      Specified by:
      remove in interface Iterator<@Nullable Object>
    • revert

      public void revert()
      Reverts the last next() call.

      After this method returns, the iteration counter is the same as before the last next() call. Calling this method multiple times decreases the iteration counter by one until the index of 0 has been reached.

    • assertEndOfType

      public void assertEndOfType() throws com.thoughtworks.xstream.converters.ConversionException
      Ensures 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, or null 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, or null 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, or null 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, or null 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