Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 56 57 package org.jdom; 58 59 import java.util.*; 60 import org.jdom.filter.*; 61 62 68 class FilterIterator implements Iterator { 69 70 private Iterator iterator; 71 private Filter filter; 72 private Object nextObject; 73 74 private static final String CVS_ID = 75 "@(#) $RCSfile: FilterIterator.java,v $ $Revision: 1.5 $ $Date: 2004/08/31 19:36:12 $ $Name: $"; 76 77 public FilterIterator(Iterator iterator, Filter filter) { 78 if ((iterator == null) || (filter == null)) { 79 throw new IllegalArgumentException ("null parameter"); 80 } 81 this.iterator = iterator; 82 this.filter = filter; 83 } 84 85 public boolean hasNext() { 86 if (nextObject != null) { 87 return true; 88 } 89 90 while (iterator.hasNext()) { 91 Object obj = iterator.next(); 92 if (filter.matches(obj)) { 93 nextObject = obj; 94 return true; 95 } 96 } 97 return false; 98 } 99 100 public Object next() { 101 if (!hasNext()) { 102 throw new NoSuchElementException(); 103 } 104 105 Object obj = nextObject; 106 nextObject = null; 107 return obj; 108 } 109 110 public void remove() { 111 iterator.remove(); 114 } 115 } 116
| Popular Tags
|