com.nitorcreations.willow.servers.IterableNodeList Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of willow-servers Show documentation
Show all versions of willow-servers Show documentation
Willow operational servlets and servers
The newest version!
package com.nitorcreations.willow.servers;
import java.util.Iterator;
import java.util.NoSuchElementException;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class IterableNodeList implements Iterable {
private NodeList list;
private int index = 0;
public IterableNodeList(NodeList list) {
this.list = list;
}
public int length() {
synchronized (list) {
return list.getLength();
}
}
public void skipNext() {
synchronized (list) {
index++;
}
}
public void skip(int nodes) {
synchronized (list) {
index += nodes;
}
}
public Node item(int index) {
synchronized (list) {
return list.item(index);
}
}
public int getLength() {
synchronized (list) {
return list.getLength();
}
}
public int getIndex() {
synchronized (list) {
return index - 1;
}
}
@Override
public Iterator iterator() {
return new Iterator() {
@Override
public boolean hasNext() {
synchronized (list) {
return index < list.getLength();
}
}
@Override
public Node next() {
synchronized (list) {
if (index >= list.getLength()) {
throw new NoSuchElementException();
}
return list.item(index++);
}
}
@Override
public void remove() {
throw new UnsupportedOperationException();
}
};
}
}