1 30 package com.hp.hpl.jena.util.iterator; 31 32 import java.util.Iterator ; 33 import java.util.NoSuchElementException ; 34 35 39 public class FilterIterator extends WrappedIterator 40 { 41 Filter f; 42 Object current; 43 boolean dead; 44 45 49 public FilterIterator( Filter fl, Iterator e) { 50 super(e); 51 f = fl; 52 current = null; 53 dead = false; 54 } 55 56 59 synchronized public boolean hasNext() { 60 if (current!=null) 61 return true; 62 while ( super.hasNext() ) { 63 current = super.next(); 64 if (f.accept(current)) 65 return true; 66 } 67 current = null; 68 dead = true; 69 return false; 70 } 71 72 76 synchronized public void remove() { 77 if ( current != null || dead ) 78 throw new IllegalStateException ( 79 "FilterIterator does not permit calls to hasNext between calls to next and remove."); 80 super.remove(); 81 } 82 83 86 synchronized public Object next() { 87 if (hasNext()) { 88 Object r = current; 89 current = null; 90 return r; 91 } 92 throw new NoSuchElementException (); 93 } 94 } 95 | Popular Tags |