1 21 24 package org.lobobrowser.html.domimpl; 25 26 import org.lobobrowser.js.*; 27 import org.w3c.dom.Node ; 28 import org.w3c.dom.NodeList ; 29 import java.util.*; 30 31 class FilteredNodeListImpl extends AbstractScriptableDelegate implements NodeList { 32 private final Collection sourceNodeList; 33 private final NodeFilter filter; 34 private final Object lock; 35 36 40 public FilteredNodeListImpl(NodeFilter filter, Collection list, Object lock) { 41 super(); 42 this.filter = filter; 43 sourceNodeList = list; 44 this.lock = lock; 45 } 46 47 public Node item(int index) { 48 synchronized(this.lock) { 49 int count = 0; 50 Iterator i = this.sourceNodeList.iterator(); 51 while(i.hasNext()) { 52 Node node = (Node ) i.next(); 53 if(this.filter.accept(node)) { 54 if(count == index) { 55 return node; 56 } 57 count++; 58 } 59 } 60 return null; 61 } 62 } 63 64 public int getLength() { 65 synchronized(this.lock) { 66 int count = 0; 67 Iterator i = this.sourceNodeList.iterator(); 68 while(i.hasNext()) { 69 Node node = (Node ) i.next(); 70 if(this.filter.accept(node)) { 71 count++; 72 } 73 } 74 return count; 75 } 76 } 77 } 78 | Popular Tags |