1 19 20 package org.netbeans.core.startup; 21 22 import java.util.Iterator ; 23 import java.util.NoSuchElementException ; 24 import org.openide.util.Lookup; 25 26 31 class LazyIterator implements Iterator <Class > { 32 Class first; 33 Class step; 34 Class <?> template; 35 Object skip; 36 Iterator delegate; 37 38 LazyIterator(Class first, Class template, Class skip) { 39 assert first != null; 40 41 this.first = first; 42 this.template = template; 43 this.skip = skip; 44 } 45 46 public boolean hasNext() { 47 if (first != null) return true; 48 49 if (delegate == null) delegate = prepareDelegate(); 51 52 if (step != null) return true; 54 55 while (delegate.hasNext() && step == null) { 57 Class next = ((Lookup.Item)delegate.next()).getType(); 58 if (next != skip) step = next; 59 } 60 61 return step != null; 62 } 63 64 public Class next() { 65 if (first != null) { 66 Class ret = first; 67 first = null; 68 return ret; 69 } 70 if (delegate == null) delegate = prepareDelegate(); 72 73 if (step != null) { 75 Class ret = step; 76 step = null; 77 return ret; 78 } 79 80 while (delegate.hasNext()) { 82 Class next = ((Lookup.Item)delegate.next()).getType(); 83 if (next != skip) return next; 84 } 85 86 throw new NoSuchElementException (); 87 } 88 89 private Iterator prepareDelegate() { 90 return Lookup.getDefault().lookupResult(template).allItems().iterator(); 91 } 92 93 public void remove() { 94 throw new UnsupportedOperationException (); 95 } 96 } 97 | Popular Tags |