aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/layoutmgr
diff options
context:
space:
mode:
authorAndreas L. Delmelle <adelmelle@apache.org>2011-02-05 00:13:18 +0000
committerAndreas L. Delmelle <adelmelle@apache.org>2011-02-05 00:13:18 +0000
commit186dd12cec2194d3187146919c09246cf410844e (patch)
tree0d1855f35ab617bb7ca8e373780ea7a98465ab00 /src/java/org/apache/fop/layoutmgr
parent0d5b2a69b9ef87ebd2c383172214673667f2a23c (diff)
downloadxmlgraphics-fop-186dd12cec2194d3187146919c09246cf410844e.tar.gz
xmlgraphics-fop-186dd12cec2194d3187146919c09246cf410844e.zip
Refactoring PositionIterator Step 1: make the class instantiable, provide default implementations for getLM() and getPos(), and make the constructor public
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1067353 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop/layoutmgr')
-rw-r--r--src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java4
-rw-r--r--src/java/org/apache/fop/layoutmgr/PositionIterator.java29
2 files changed, 24 insertions, 9 deletions
diff --git a/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java b/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
index c4c4a466c..71790ec82 100644
--- a/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
+++ b/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
@@ -51,6 +51,7 @@ public class KnuthPossPosIter extends PositionIterator {
// Check position < endPos
/** {@inheritDoc} */
+ @Override
protected boolean checkNext() {
if (iterCount > 0) {
return super.checkNext();
@@ -61,6 +62,7 @@ public class KnuthPossPosIter extends PositionIterator {
}
/** {@inheritDoc} */
+ @Override
public Position next() {
--iterCount;
return super.next();
@@ -75,11 +77,13 @@ public class KnuthPossPosIter extends PositionIterator {
}
/** {@inheritDoc} */
+ @Override
protected LayoutManager getLM(Object nextObj) {
return ((ListElement) nextObj).getLayoutManager();
}
/** {@inheritDoc} */
+ @Override
protected Position getPos(Object nextObj) {
return ((ListElement) nextObj).getPosition();
}
diff --git a/src/java/org/apache/fop/layoutmgr/PositionIterator.java b/src/java/org/apache/fop/layoutmgr/PositionIterator.java
index f88142613..b2bf404ff 100644
--- a/src/java/org/apache/fop/layoutmgr/PositionIterator.java
+++ b/src/java/org/apache/fop/layoutmgr/PositionIterator.java
@@ -28,12 +28,11 @@ import java.util.NoSuchElementException;
* {@code PositionIterator}, or an iterator over {@link KnuthElement}s,
* for example.<br/>
* The {@link #next()} method always returns a {@link Position}. The
- * protected {@link #getLM(Object)} and {@link #getPos(Object)} methods
- * must be overridden in subclasses to take care of obtaining the
- * {@link LayoutManager} or {@link Position} from the object returned
- * by the parent iterator's {@code next()} method.
+ * {@link #getPos(Object)} method can be overridden in subclasses
+ * to take care of obtaining the {@link LayoutManager} or {@link Position}
+ * from the object returned by the parent iterator's {@code next()} method.
*/
-public abstract class PositionIterator implements Iterator<Position> {
+public class PositionIterator implements Iterator<Position> {
private Iterator parentIter;
private Object nextObj;
@@ -44,7 +43,7 @@ public abstract class PositionIterator implements Iterator<Position> {
* Construct position iterator.
* @param parentIter an iterator to use as parent
*/
- protected PositionIterator(Iterator parentIter) {
+ public PositionIterator(Iterator parentIter) {
this.parentIter = parentIter;
lookAhead();
//checkNext();
@@ -64,13 +63,25 @@ public abstract class PositionIterator implements Iterator<Position> {
* @param nextObj next object from which to obtain position
* @return layout manager
*/
- protected abstract LayoutManager getLM(Object nextObj);
+ protected LayoutManager getLM(Object nextObj) {
+ return getPos(nextObj).getLM();
+ }
/**
+ * Default implementation assumes that the passed
+ * {@code nextObj} is itself a {@link Position}, and just returns it.
+ * Subclasses for which this is not the case, <em>must</em> provide a
+ * suitable override this method.
* @param nextObj next object from which to obtain position
- * @return position of next object
+ * @return position of next object.
*/
- protected abstract Position getPos(Object nextObj);
+ protected Position getPos(Object nextObj) {
+ if (nextObj instanceof Position) {
+ return (Position)nextObj;
+ }
+ throw new IllegalArgumentException(
+ "Cannot obtain Position from the given object.");
+ }
private void lookAhead() {
if (parentIter.hasNext()) {