36 lines
974 B
Java
36 lines
974 B
Java
package com.github.dtschust.zork.parser.dom;
|
|
|
|
import org.w3c.dom.Element;
|
|
import org.w3c.dom.Node;
|
|
import org.w3c.dom.NodeList;
|
|
|
|
import java.util.AbstractList;
|
|
import java.util.RandomAccess;
|
|
|
|
public class DOMElementList extends AbstractList<DOMElement> implements RandomAccess {
|
|
private final NodeList list;
|
|
|
|
private DOMElementList(final NodeList l) {
|
|
list = l;
|
|
}
|
|
|
|
static DOMElementList byTagName(final Element parent, final String name) {
|
|
return new DOMElementList(parent.getElementsByTagName(name));
|
|
}
|
|
|
|
@Override
|
|
public DOMElement get(int index) {
|
|
final Node e = list.item(index);
|
|
if (!(e instanceof Element)) {
|
|
// the contract of getElementsByTagName states that it returns a list of Element objects
|
|
throw new IllegalStateException("unreachable");
|
|
}
|
|
return DOMElement.of((Element) e);
|
|
}
|
|
|
|
@Override
|
|
public int size() {
|
|
return list.getLength();
|
|
}
|
|
}
|