1 package uk.co.jezuk.mango.iterators; 2 3 10 public class SelectingIterator implements java.util.Iterator 11 { 12 public SelectingIterator(java.util.Iterator iterator, uk.co.jezuk.mango.Predicate predicate) 13 { 14 iter_ = iterator; 15 pred_ = predicate; 16 } 18 public boolean hasNext() 19 { 20 next_ = null; 21 while(iter_.hasNext() && next_ == null) 22 { 23 Object candidate = iter_.next(); 24 if(pred_.test(candidate)) 25 next_ = candidate; 26 } return next_ != null; 28 } 30 public Object next() 31 { 32 return next_; 33 } 35 public void remove() 36 { 37 iter_.remove(); 38 } 40 private java.util.Iterator iter_; 42 private uk.co.jezuk.mango.Predicate pred_; 43 private Object next_; 44 } 46 47 | Popular Tags |