com.databasesandlife.util.DomNodeListIterable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of java-common Show documentation
Show all versions of java-common Show documentation
Utility classes developed at Adrian Smith Software (A.S.S.)
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();
}
}