1 package prefuse.data.util; 2 3 import java.util.BitSet ; 4 import java.util.NoSuchElementException ; 5 6 import prefuse.util.collections.IntIterator; 7 8 15 public class UniqueRowIterator extends IntIterator { 16 17 private IntIterator m_iter; 18 private int m_next; 19 private BitSet m_visited; 20 21 25 public UniqueRowIterator(IntIterator iter) { 26 m_iter = iter; 27 m_visited = new BitSet (); 28 advance(); 29 } 30 31 private void advance() { 32 int r = -1; 33 while ( r == -1 && m_iter.hasNext() ) { 34 r = m_iter.nextInt(); 35 if ( visit(r) ) 36 r = -1; 37 } 38 m_next = r; 39 } 40 41 private boolean visit(int row) { 42 if ( m_visited.get(row) ) { 43 return true; 44 } else { 45 m_visited.set(row); 46 return false; 47 } 48 } 49 50 53 public boolean hasNext() { 54 return m_next != -1; 55 } 56 57 60 public int nextInt() { 61 if ( m_next == -1 ) 62 throw new NoSuchElementException (); 63 int retval = m_next; 64 advance(); 65 return retval; 66 } 67 68 72 public void remove() { 73 throw new UnsupportedOperationException (); 74 } 75 76 } | Popular Tags |