1 package prefuse.data.util; 2 3 import java.util.NoSuchElementException ; 4 5 import prefuse.data.Table; 6 import prefuse.data.expression.Predicate; 7 import prefuse.util.collections.IntIterator; 8 9 16 public class FilterRowIterator extends IntIterator { 17 18 private Predicate predicate; 19 private IntIterator rows; 20 private Table t; 21 private int next; 22 23 29 public FilterRowIterator(IntIterator rows, Table t, Predicate p) { 30 this.predicate = p; 31 this.rows = rows; 32 this.t = t; 33 next = advance(); 34 } 35 36 private int advance() { 37 while ( rows.hasNext() ) { 38 int r = rows.nextInt(); 39 if ( predicate.getBoolean(t.getTuple(r)) ) { 40 return r; 41 } 42 } 43 rows = null; 44 next = -1; 45 return -1; 46 } 47 48 51 public int nextInt() { 52 if ( !hasNext() ) { 53 throw new NoSuchElementException ("No more elements"); 54 } 55 int retval = next; 56 next = advance(); 57 return retval; 58 } 59 60 63 public boolean hasNext() { 64 return ( rows != null ); 65 } 66 67 71 public void remove() { 72 throw new UnsupportedOperationException (); 73 } 74 75 } | Popular Tags |