Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

PositionIterator.java 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.layoutmgr;
  8. import java.util.Iterator;
  9. import java.util.NoSuchElementException;
  10. public abstract class PositionIterator implements Iterator {
  11. Iterator m_parentIter;
  12. Object m_nextObj;
  13. LayoutManager m_childLM;
  14. boolean m_bHasNext;
  15. PositionIterator(Iterator parentIter) {
  16. m_parentIter = parentIter;
  17. lookAhead();
  18. //checkNext();
  19. }
  20. public LayoutManager getNextChildLM() {
  21. // Move to next "segment" of iterator, ie: new childLM
  22. if (m_childLM == null && m_nextObj != null) {
  23. m_childLM = getLM(m_nextObj);
  24. m_bHasNext = true;
  25. }
  26. return m_childLM;
  27. }
  28. protected abstract LayoutManager getLM(Object nextObj);
  29. protected abstract Position getPos(Object nextObj);
  30. private void lookAhead() {
  31. if (m_parentIter.hasNext()) {
  32. m_bHasNext = true;
  33. m_nextObj = m_parentIter.next();
  34. } else {
  35. endIter();
  36. }
  37. }
  38. protected boolean checkNext() {
  39. LayoutManager lm = getLM(m_nextObj);
  40. if (m_childLM == null) {
  41. m_childLM = lm;
  42. } else if (m_childLM != lm) {
  43. // End of this sub-sequence with same child LM
  44. m_bHasNext = false;
  45. m_childLM = null;
  46. return false;
  47. }
  48. return true;
  49. }
  50. protected void endIter() {
  51. m_bHasNext = false;
  52. m_nextObj = null;
  53. m_childLM = null;
  54. }
  55. public boolean hasNext() {
  56. return (m_bHasNext && checkNext());
  57. }
  58. public Object next() throws NoSuchElementException {
  59. if (m_bHasNext) {
  60. Object retObj = getPos(m_nextObj);
  61. lookAhead();
  62. return retObj;
  63. } else {
  64. throw new NoSuchElementException("PosIter");
  65. }
  66. }
  67. protected Object peekNext() {
  68. return m_nextObj;
  69. }
  70. public void remove() throws UnsupportedOperationException {
  71. throw new UnsupportedOperationException("PositionIterator doesn't support remove");
  72. }
  73. }