pbwest 2004/02/11 22:42:45 Modified: src/java/org/apache/fop/fo/pagination Tag: FOP_0-20-0_Alt-Design PageSequenceMaster.java Log: Moved usageCount and useConditionalMaster() from PageMasterAlternatives to PageMasterIterator. Changed iterator from post-increment to pre-increment: initialized master index to -1; modified hasNext() to check for exhaustion of final master. Made PageMasterIterator cloneable: removed finished[] array; synchronized updates of usageCount and currentMasterIndex. Revision Changes Path No revision No revision 1.1.2.6 +59 -49 xml-fop/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java Index: PageSequenceMaster.java =================================================================== RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/pagination/PageSequenceMaster.java,v retrieving revision 1.1.2.5 retrieving revision 1.1.2.6 diff -u -r1.1.2.5 -r1.1.2.6 --- PageSequenceMaster.java 11 Feb 2004 06:38:18 -0000 1.1.2.5 +++ PageSequenceMaster.java 12 Feb 2004 06:42:45 -0000 1.1.2.6 @@ -20,6 +20,7 @@ import java.util.ArrayList; import java.util.HashMap; + import org.apache.fop.apps.FOPException; import org.apache.fop.datatypes.EnumType; import org.apache.fop.datatypes.IntegerType; @@ -31,6 +32,7 @@ import org.apache.fop.fo.PropNames; import org.apache.fop.fo.expr.PropertyException; import org.apache.fop.fo.pagination.FoPageSequenceMaster.FoRepeatablePageMasterAlternatives.FoConditionalPageMasterReference; +import org.apache.fop.fo.pagination.PageSequenceMaster.PageMasterAlternatives.PageCondition; import org.apache.fop.fo.properties.BlankOrNotBlank; import org.apache.fop.fo.properties.MaximumRepeats; import org.apache.fop.fo.properties.OddOrEven; @@ -307,11 +309,6 @@ public final int minRepeats; /** The maximum-repeats value for this set of alternatives. */ public final int maxRepeats; - - /** - * Number of times this set of alternatives has been used - */ - private int usageCount = 0; /** * List of alternative condition sets/simple page masters @@ -376,34 +373,6 @@ } /** - * Use the simple page master from the first <code>PageCondition</code> - * matching the argument. - * The usage count for this <code>PageMasterAlternatives</code> - * object is incremented. - * @param blankOrNot blank or not blank page test condition - * @param oddOrEven odd or even page numbered page test condition - * @param pagePosition position on sequence test condition - * @return the simple page master or null if the usage count has been - * exceeded or there is no matching set of conditions. - */ - public FoSimplePageMaster useConditionalMaster( - int blankOrNot, int oddOrEven, int pagePosition) { - if (maxRepeats == NO_LIMIT || usageCount < maxRepeats) { - PageCondition pageCond = conditionMatch( - blankOrNot, oddOrEven, pagePosition); - if (pageCond != null) { - usageCount++; - return pageCond.getSimplePM(); - } - } - return null; - } - - public boolean isExhausted() { - return (maxRepeats != NO_LIMIT && usageCount >= maxRepeats); - } - - /** * Encodes a condition set from an FoConditionalPageReferenceMaster. */ public class PageCondition { @@ -481,9 +450,10 @@ } return null; } - } - } + } // End of PageCondition + + } // End of PageMasterAlternatives /** * Provides an iterator across the sequence of page masters in the @@ -492,36 +462,69 @@ * @author pbw * @version $Revision$ $Name$ */ - public class PageMasterIterator { + public class PageMasterIterator implements Cloneable { /** * Effectively, the iterator across <code>masters</code> */ - private int currentMasterIndex = 0; - - private PageMasterAlternatives altMaster = - (PageMasterAlternatives)(masters.get(currentMasterIndex)); + private int currentMasterIndex = -1; /** - * Array of flags for completed masters + * Number of times this set of alternatives has been used */ - private boolean[] finished = new boolean[masters.size()]; + private int usageCount = 0; + + private PageMasterAlternatives altMaster; /** * Returns a new iterator across <code>masters</code> */ - public PageMasterIterator() { - } + public PageMasterIterator() {} /** - * @return true if any repetitions on any masters remian in the + * @return true if any repetitions on any masters remain in the * sequence */ public boolean hasNext() { if (currentMasterIndex >= masters.size()) return false; + if (currentMasterIndex == masters.size() - 1 + && currentExhausted()) return false; return true; } - + + /** + * Use the simple page master from the first <code>PageCondition</code> + * matching the argument. + * The usage count for this <code>PageMasterAlternatives</code> + * object is incremented. + * @param blankOrNot blank or not blank page test condition + * @param oddOrEven odd or even page numbered page test condition + * @param pagePosition position on sequence test condition + * @return the simple page master or null if the usage count has been + * exceeded or there is no matching set of conditions. + */ + public FoSimplePageMaster useConditionalMaster( + int blankOrNot, int oddOrEven, int pagePosition) { + if (altMaster.maxRepeats == NO_LIMIT + || usageCount < altMaster.maxRepeats) { + PageCondition pageCond = altMaster.conditionMatch( + blankOrNot, oddOrEven, pagePosition); + if (pageCond != null) { + synchronized (this) { + usageCount++; + } + return pageCond.getSimplePM(); + } + } + return null; + } + + public boolean currentExhausted() { + return (currentMasterIndex < 0 || + (altMaster.maxRepeats != NO_LIMIT + && usageCount >= altMaster.maxRepeats)); + } + /** * Gets the next simple page master matching the given conditions. * @param blankOrNot blank or not blank page test condition @@ -534,12 +537,19 @@ PageMasterAlternatives masterAlt; FoSimplePageMaster simplePM; while (hasNext()) { - simplePM = altMaster.useConditionalMaster( + if (currentExhausted()) { + synchronized (this) { + // Iterate to next altMaster + altMaster = (PageMasterAlternatives)( + masters.get(++currentMasterIndex)); + usageCount = 0; + } + } + simplePM = useConditionalMaster( blankOrNot, oddOrEven, pagePosition); if (simplePM != null) { return simplePM; } - finished[currentMasterIndex++] = true; } return null; } @@ -553,6 +563,6 @@ BlankOrNotBlank.ANY, OddOrEven.ANY, PagePosition.ANY); } - } + } // End of PageMasterIterator }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]