1 package org.bsf.smartValueObject.container; 2 3 import org.bsf.smartValueObject.VersionableFilter; 4 import org.bsf.smartValueObject.Versionable; 5 6 import java.util.*; 7 8 18 public class SmartIterator implements Iterator { 19 20 private static final Object NOOBJECT = new Object (); 21 22 private Iterator it; 23 private Object next = NOOBJECT; 24 25 private VersionableFilter filter; 26 27 34 public SmartIterator(Iterator it, VersionableFilter f) { 35 this.it = it; 36 this.filter = f; 37 } 38 39 public boolean hasNext() { 40 while (it.hasNext()) { 41 next = it.next(); 42 if (next instanceof Versionable) { 43 if (!filter.accept((Versionable)next)) { 44 continue; 46 } else { 47 return true; 48 } 49 } else { 50 continue; 52 } 53 } 54 return false; 55 } 56 57 public Object next() { 58 if (next == NOOBJECT) { 59 if (!hasNext()) { 60 throw new NoSuchElementException(); 61 } 62 63 Object temp = next; 64 next = NOOBJECT; 65 return temp; 66 67 } else { 68 return next; 69 } 70 } 71 72 75 public void remove() { 76 throw new UnsupportedOperationException (); 77 } 78 } 79 | Popular Tags |