1 19 20 21 package org.netbeans.tax.dom; 22 23 import java.util.Iterator ; 24 import org.w3c.dom.*; 25 import org.netbeans.tax.*; 26 27 33 class NodeListImpl implements NodeList { 34 35 public static final NodeList EMPTY = new NodeList() { 36 public int getLength() { return 0; } 37 public org.w3c.dom.Node item(int i) { return null; } 38 public String toString() { return "NodeListImpl.EMPTY"; } 39 }; 40 41 42 private final TreeObjectList peer; 43 44 public NodeListImpl(TreeObjectList peer) { 45 this.peer = peer; 46 } 47 48 52 public int getLength() { 53 int i = 0; 54 Iterator it = peer.iterator(); 55 while (it.hasNext()) { 56 TreeObject next = (TreeObject) it.next(); 57 if (accept(next)) i++; 58 } 59 return i; 60 } 61 62 71 public Node item(int index) { 72 int i = 0; 73 Iterator it = peer.iterator(); 74 while (it.hasNext()) { 75 TreeObject next = (TreeObject) it.next(); 76 if (accept(next)) { 77 if (i == index) { 78 return Wrapper.wrap((TreeObject)peer.get(index)); 79 } else { 80 i++; 81 } 82 } 83 } 84 return null; 85 } 86 87 90 private boolean accept(TreeObject o) { 91 return o instanceof TreeText || o instanceof TreeElement; 92 } 93 } 94 | Popular Tags |