1 17 18 19 20 package org.apache.fop.layoutmgr; 21 22 import java.util.Iterator ; 23 import java.util.NoSuchElementException ; 24 25 public abstract class PositionIterator implements Iterator { 26 27 private Iterator parentIter; 28 private Object nextObj; 29 private LayoutManager childLM; 30 private boolean bHasNext; 31 32 protected PositionIterator(Iterator pIter) { 33 parentIter = pIter; 34 lookAhead(); 35 } 37 38 public LayoutManager getNextChildLM() { 39 if (childLM == null && nextObj != null) { 41 childLM = getLM(nextObj); 42 bHasNext = true; 43 } 44 return childLM; 45 } 46 47 protected abstract LayoutManager getLM(Object nextObj); 48 49 protected abstract Position getPos(Object nextObj); 50 51 private void lookAhead() { 52 if (parentIter.hasNext()) { 53 bHasNext = true; 54 nextObj = parentIter.next(); 55 } else { 56 endIter(); 57 } 58 } 59 60 protected boolean checkNext() { 61 LayoutManager lm = getLM(nextObj); 62 if (childLM == null) { 63 childLM = lm; 64 } else if (childLM != lm && lm != null) { 65 bHasNext = false; 67 childLM = null; 68 return false; 69 } 70 return true; 71 } 72 73 protected void endIter() { 74 bHasNext = false; 75 nextObj = null; 76 childLM = null; 77 } 78 79 public boolean hasNext() { 80 return (bHasNext && checkNext()); 81 } 82 83 84 public Object next() throws NoSuchElementException { 85 if (bHasNext) { 86 Object retObj = getPos(nextObj); 87 lookAhead(); 88 return retObj; 89 } else { 90 throw new NoSuchElementException ("PosIter"); 91 } 92 } 93 94 public Object peekNext() { 95 return nextObj; 96 } 97 98 public void remove() throws UnsupportedOperationException { 99 throw new UnsupportedOperationException ("PositionIterator doesn't support remove"); 100 } 101 } 102 103 | Popular Tags |