1 28 29 package com.caucho.xml; 30 31 import com.caucho.util.CharBuffer; 32 import com.caucho.xpath.pattern.NodeListIterator; 33 34 import org.w3c.dom.Node ; 35 import org.w3c.dom.NodeList ; 36 37 import java.util.ArrayList ; 38 import java.util.Collection ; 39 import java.util.Iterator ; 40 41 44 public class NodeListImpl implements NodeList { 45 private ArrayList <Node > _nodeList = new ArrayList <Node >(); 46 47 50 public NodeListImpl() 51 { 52 } 53 54 57 public NodeListImpl(Collection <Node > collection) 58 { 59 _nodeList.addAll(collection); 60 } 61 62 65 public void add(Node node) 66 { 67 _nodeList.add(node); 68 } 69 70 73 public Node item(int index) 74 { 75 if (index < 0 || _nodeList.size() <= index) 76 return null; 77 78 return _nodeList.get(index); 79 } 80 81 84 public int getLength() 85 { 86 return _nodeList.size(); 87 } 88 89 public String toString() 90 { 91 CharBuffer cb = new CharBuffer(); 92 93 cb.append("NodeListImpl["); 94 for (int i = 0; i < getLength(); i++) { 95 if (i != 0) 96 cb.append(", "); 97 cb.append(item(i)); 98 } 99 cb.append("]"); 100 101 return cb.toString(); 102 } 103 104 public Iterator<Node > iterator() 106 { 107 return new NodeListIterator(null, this); 108 } 109 } 110 | Popular Tags |