Home | History | Annotate | Download | only in util
      1 package org.unicode.cldr.util;
      2 
      3 import java.util.Iterator;
      4 
      5 import org.w3c.dom.Node;
      6 import org.w3c.dom.NodeList;
      7 
      8 /**
      9  * NodeLists as returned by DOM do not support Iterators; they can be accessed by index.
     10  * This is a small helper class that wraps a NodeList and makes it support the Iterator interface.
     11  *
     12  * The iterator does not support item removal.
     13  *
     14  * @author ribnitz
     15  *
     16  */
     17 public class NodeListIterator implements Iterator<Node> {
     18     /**
     19      * The NodeList to work on
     20      */
     21     private NodeList nodeList;
     22     /**
     23      * Since node lists are indexed by position, the current
     24      * position
     25      */
     26     private int currentPos = 0;
     27 
     28     public NodeListIterator(NodeList aNodeList) {
     29         nodeList = aNodeList;
     30     }
     31 
     32     @Override
     33     public boolean hasNext() {
     34         return (currentPos < nodeList.getLength());
     35     }
     36 
     37     @Override
     38     public Node next() {
     39         return nodeList.item(currentPos++);
     40     }
     41 
     42     @Override
     43     public void remove() {
     44         throw new UnsupportedOperationException("This iterator does not support item removal");
     45     }
     46 
     47 }