You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ad...@apache.org on 2011/02/05 01:13:19 UTC

svn commit: r1067353 - in /xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr: KnuthPossPosIter.java PositionIterator.java

Author: adelmelle
Date: Sat Feb  5 00:13:18 2011
New Revision: 1067353

URL: http://svn.apache.org/viewvc?rev=1067353&view=rev
Log:
Refactoring PositionIterator Step 1: make the class instantiable, provide default implementations for getLM() and getPos(), and make the constructor public

Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PositionIterator.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java?rev=1067353&r1=1067352&r2=1067353&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/KnuthPossPosIter.java Sat Feb  5 00:13:18 2011
@@ -51,6 +51,7 @@ public class KnuthPossPosIter extends Po
     // Check position < endPos
 
     /** {@inheritDoc} */
+    @Override
     protected boolean checkNext() {
         if (iterCount > 0) {
             return super.checkNext();
@@ -61,6 +62,7 @@ public class KnuthPossPosIter extends Po
     }
 
     /** {@inheritDoc} */
+    @Override
     public Position next() {
         --iterCount;
         return super.next();
@@ -75,11 +77,13 @@ public class KnuthPossPosIter extends Po
     }
 
     /** {@inheritDoc} */
+    @Override
     protected LayoutManager getLM(Object nextObj) {
         return ((ListElement) nextObj).getLayoutManager();
     }
 
     /** {@inheritDoc} */
+    @Override
     protected Position getPos(Object nextObj) {
         return ((ListElement) nextObj).getPosition();
     }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PositionIterator.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PositionIterator.java?rev=1067353&r1=1067352&r2=1067353&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PositionIterator.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/layoutmgr/PositionIterator.java Sat Feb  5 00:13:18 2011
@@ -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 i
      * 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 i
      * @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()) {



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org