1 6 7 package com.hp.hpl.jena.util.iterator; 8 9 import java.util.*; 10 11 17 18 public class MapFilterIterator extends NiceIterator implements ExtendedIterator 19 { 20 MapFilter f; 21 Object current; 22 boolean dead; 23 ClosableIterator underlying; 24 25 29 public MapFilterIterator( MapFilter fl, ExtendedIterator e) { 30 f = fl; 31 current = null; 32 dead = false; 33 underlying = e; 34 } 35 36 39 synchronized public boolean hasNext() { 40 if (current!=null) 41 return true; 42 while ( underlying.hasNext() ) { 43 current = f.accept( underlying.next() ); 44 if (current != null) 45 return true; 46 } 47 current = null; 48 dead = true; 49 return false; 50 } 51 52 public void close() 53 { 54 underlying.close(); 55 } 56 57 61 synchronized public void remove() { 62 if ( current != null || dead ) 63 throw new IllegalStateException ( 64 "FilterIterator does not permit calls to hasNext between calls to next and remove."); 65 66 underlying.remove(); 67 } 68 71 synchronized public Object next() { 72 if (hasNext()) { 73 Object r = current; 74 current = null; 75 return r; 76 } 77 throw new NoSuchElementException(); 78 } 79 } 80 81 82 111 | Popular Tags |