All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.databasesandlife.util.DomNodeListIterable Maven / Gradle / Ivy

The newest version!
package com.databasesandlife.util;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import javax.annotation.Nonnull;
import java.util.Iterator;
import java.util.NoSuchElementException;

public class DomNodeListIterable implements Iterable {

    protected @Nonnull NodeList nodes;

    protected class NodeIterator implements Iterator {
        int next = 0;

        @Override
        public boolean hasNext() {
            return next < nodes.getLength();
        }

        @Override
        public Node next() {
            if ( ! hasNext()) throw new NoSuchElementException();

            var result = nodes.item(next);
            next++;
            return result;
        }
    }
    
    public DomNodeListIterable(@Nonnull NodeList nodes) { this.nodes = nodes; }

    @Override
    public @Nonnull Iterator iterator() {
        return new NodeIterator();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy