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 vh...@apache.org on 2013/09/04 22:32:32 UTC

svn commit: r1520134 - in /xmlgraphics/fop/branches/Temp_WhitespaceManagement: src/java/org/apache/fop/fo/ src/java/org/apache/fop/fo/extensions/ src/java/org/apache/fop/layoutmgr/ test/java/org/apache/fop/

Author: vhennebert
Date: Wed Sep  4 20:32:32 2013
New Revision: 1520134

URL: http://svn.apache.org/r1520134
Log:
FOP-2293: Second patch by Seifeddine Dridi
Some adjustments and a lot of Checkstyle fixes

Added:
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/Alternative.java   (with props)
Removed:
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/AlternativeManager.java
Modified:
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/Constants.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/FOPropertyMapping.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/AlternativeBlock.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/BestFit.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/AlternativeBlockLayoutManager.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutManager.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/ElementListUtils.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/LayoutContext.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
    xmlgraphics/fop/branches/Temp_WhitespaceManagement/test/java/org/apache/fop/KnuthAlgorithmTestCase.java

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/Constants.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/Constants.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/Constants.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/Constants.java Wed Sep  4 20:32:32 2013
@@ -815,7 +815,7 @@ public interface Constants {
 
     /** Scope for table header */
     int PR_X_HEADER_COLUMN = 290;
-    
+
     /** Property constant - FOP proprietary*/
     int PR_X_FITTING_STRATEGY = 291;
 

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/FOPropertyMapping.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/FOPropertyMapping.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/FOPropertyMapping.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/FOPropertyMapping.java Wed Sep  4 20:32:32 2013
@@ -581,6 +581,7 @@ public final class FOPropertyMapping imp
 
         // background-color
         m  = new ColorProperty.Maker(PR_BACKGROUND_COLOR) {
+            @Override
             protected Property convertPropertyDatatype(
                     Property p, PropertyList propertyList, FObj fo) throws PropertyException {
                 String nameval = p.getNCname();
@@ -1620,6 +1621,7 @@ public final class FOPropertyMapping imp
 
         // text-align TODO: make it a StringProperty with enums.
         m  = new EnumProperty.Maker(PR_TEXT_ALIGN) {
+            @Override
             public Property get(int subpropId, PropertyList propertyList,
                     boolean bTryInherit, boolean bTryDefault) throws PropertyException {
                 Property p = super.get(subpropId, propertyList, bTryInherit, bTryDefault);
@@ -1649,6 +1651,7 @@ public final class FOPropertyMapping imp
 
         // text-align-last
         m  = new EnumProperty.Maker(PR_TEXT_ALIGN_LAST) {
+            @Override
             public Property get(int subpropId, PropertyList propertyList,
                     boolean bTryInherit, boolean bTryDefault) throws PropertyException {
                 Property p = super.get(subpropId, propertyList, bTryInherit, bTryDefault);
@@ -2613,7 +2616,7 @@ public final class FOPropertyMapping imp
         m.setInherited(false);
         m.setDefault("");
         addPropertyMaker("fox:alt-text", m);
-        
+
         //fox:fitting-strategy, used only in fox:best-fit
         m = new StringProperty.Maker(PR_X_FITTING_STRATEGY);
         m.setInherited(false);

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/AlternativeBlock.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/AlternativeBlock.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/AlternativeBlock.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/AlternativeBlock.java Wed Sep  4 20:32:32 2013
@@ -40,6 +40,7 @@ public class AlternativeBlock extends FO
         super(parent);
     }
 
+    @Override
     public void processNode(String elementName, Locator locator,
             Attributes attlist, PropertyList pList) throws FOPException {
         if (log.isDebugEnabled()) {
@@ -48,29 +49,33 @@ public class AlternativeBlock extends FO
         }
     }
 
+    @Override
     public void startOfNode() throws FOPException {
-        if (log.isDebugEnabled())
+        if (log.isDebugEnabled()) {
             log.debug("AlternativeBlock.startOfNode()");
+        }
     }
 
+    @Override
     public void endOfNode() throws FOPException {
-        if (log.isDebugEnabled())
+        if (log.isDebugEnabled()) {
             log.debug("AlternativeBlock.endOfNode()");
+        }
     }
 
     /**
      * Content model: see {@link Block}
      */
+    @Override
     protected void validateChildNode(Locator loc, String nsURI, String localName)
             throws ValidationException {
         if (FOX_URI.equals(nsURI)) {
             if ("best-fit".equals(localName) || "alternative-block".equals(localName)) {
                 invalidChildError(loc, FOX_URI, localName);
             }
-        }
-        else if (FO_URI.equals(nsURI)) {
+        } else if (FO_URI.equals(nsURI)) {
             if (!isBlockOrInlineItem(nsURI, localName)) {
-                invalidChildError(loc, FO_URI, localName);
+                invalidChildError(loc, nsURI, localName);
             }
         }
     }
@@ -85,6 +90,7 @@ public class AlternativeBlock extends FO
         return ExtensionElementMapping.STANDARD_PREFIX;
     }
 
+    @Override
     public String getNamespaceURI() {
         return ExtensionElementMapping.URI;
     }

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/BestFit.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/BestFit.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/BestFit.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/BestFit.java Wed Sep  4 20:32:32 2013
@@ -19,7 +19,6 @@
 
 package org.apache.fop.fo.extensions;
 
-import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 
 import org.apache.fop.apps.FOPException;
@@ -27,7 +26,7 @@ import org.apache.fop.fo.FONode;
 import org.apache.fop.fo.FObj;
 import org.apache.fop.fo.PropertyList;
 import org.apache.fop.fo.ValidationException;
-import org.apache.fop.layoutmgr.AlternativeManager.FittingStrategy;
+import org.apache.fop.layoutmgr.Alternative.FittingStrategy;
 
 /**
  *  A class that holds a set of <fox:alternative-block> blocks where each one is examined,
@@ -46,52 +45,50 @@ public class BestFit extends FObj {
     }
 
     /** {@inheritDoc} */
+    @Override
     public void bind(PropertyList pList) throws FOPException {
         super.bind(pList);
         String strategyName = pList.get(PR_X_FITTING_STRATEGY).getString();
-        if (strategyName.equals("first-fit"))
-            strategy = FittingStrategy.FIRST_FIT;
-        else if (strategyName.equals("smallest-fit"))
-            strategy = FittingStrategy.SMALLEST_FIT;
-        else if (strategyName.equals("biggest-fit"))
-            strategy = FittingStrategy.BIGGEST_FIT;
-        else {
-            log.warn("Unrecognized strategy name => " + strategyName + ". Using default strategy (first-fit");
-            strategy = FittingStrategy.FIRST_FIT;
+        for (FittingStrategy fs : FittingStrategy.values()) {
+            if (fs.getStrategyName().equals(strategyName)) {
+                strategy = fs;
+                return;
+            }
         }
-
-    }
-
-    public void processNode(String elementName, Locator locator,
-            Attributes attlist, PropertyList pList) throws FOPException {
-        if (log.isDebugEnabled()) {
-            log.debug("org.apache.fop.fo.extensions.BestFit: " + elementName
-                    + (locator != null ? " at " + getLocatorString(locator) : ""));
+        if (log.isWarnEnabled()) {
+            log.warn("Unrecognized strategy name => " + strategyName + ". Using default strategy (first-fit");
         }
-        pList.addAttributesToList(attlist);
-        bind(pList);
     }
 
+    @Override
     public void startOfNode() throws FOPException {
-        if (log.isDebugEnabled())
+        super.startOfNode();
+        if (log.isDebugEnabled()) {
             log.debug("BestFit.startOfNode()");
+        }
     }
 
+    @Override
     public void endOfNode() throws FOPException {
-        if (log.isDebugEnabled())
+        super.endOfNode();
+        if (log.isDebugEnabled()) {
             log.debug("BestFit.endOfNode()");
+        }
     }
 
     /**
      * {@inheritDoc}
      * Content model: (fox:alternative-block)+
      */
+    @Override
     protected void validateChildNode(Locator loc, String nsURI, String localName)
             throws ValidationException {
-        if (FO_URI.equals(nsURI)) {
+        if (FOX_URI.equals(nsURI)) {
             if (!"alternative-block".equals(localName)) {
-                invalidChildError(loc, FO_URI, localName);
+                invalidChildError(loc, FOX_URI, localName);
             }
+        } else {
+            invalidChildError(loc, nsURI, localName);
         }
     }
 
@@ -105,6 +102,7 @@ public class BestFit extends FObj {
         return ExtensionElementMapping.STANDARD_PREFIX;
     }
 
+    @Override
     public String getNamespaceURI() {
         return ExtensionElementMapping.URI;
     }

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/fo/extensions/ExtensionElementMapping.java Wed Sep  4 20:32:32 2013
@@ -79,6 +79,7 @@ public class ExtensionElementMapping ext
     /**
      * Initialize the data structures.
      */
+    @Override
     protected void initialize() {
         if (foObjs == null) {
             foObjs = new HashMap<String, Maker>();
@@ -92,35 +93,41 @@ public class ExtensionElementMapping ext
     }
 
     static class DestinationMaker extends ElementMapping.Maker {
+        @Override
         public FONode make(FONode parent) {
             return new Destination(parent);
         }
     }
 
     static class ExternalDocumentMaker extends ElementMapping.Maker {
+        @Override
         public FONode make(FONode parent) {
             return new ExternalDocument(parent);
         }
     }
-    
+
     static class BestFitMaker extends ElementMapping.Maker {
+        @Override
         public FONode make(FONode parent) {
             return new BestFit(parent);
         }
     }
-    
+
     static class AlternativeBlockMaker extends ElementMapping.Maker {
+        @Override
         public FONode make(FONode parent) {
             return new AlternativeBlock(parent);
         }
     }
 
     /** {@inheritDoc} */
+    @Override
     public String getStandardPrefix() {
         return STANDARD_PREFIX;
     }
 
     /** {@inheritDoc} */
+    @Override
     public boolean isAttributeProperty(QName attributeName) {
         if (!URI.equals(attributeName.getNamespaceURI())) {
             throw new IllegalArgumentException("The namespace URIs don't match");

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/AbstractBreaker.java Wed Sep  4 20:32:32 2013
@@ -107,9 +107,9 @@ public abstract class AbstractBreaker {
          * of previous BlockSequence?), EN_COLUMN, EN_ODD_PAGE,
          * EN_EVEN_PAGE.
          */
-        private int startOn;
+        private final int startOn;
 
-        private int displayAlign;
+        private final int displayAlign;
 
         /**
          * Creates a new BlockSequence.
@@ -142,6 +142,7 @@ public abstract class AbstractBreaker {
          * Finalizes a Knuth sequence.
          * @return a finalized sequence.
          */
+        @Override
         public KnuthSequence endSequence() {
             return endSequence(null);
         }
@@ -611,7 +612,6 @@ public abstract class AbstractBreaker {
                 // Handle SpaceHandling(Break)Positions, see SpaceResolver!
                 SpaceResolver.performConditionalsNotification(effectiveList,
                         startElementIndex, notificationEndElementIndex, lastBreak);
-                childLC.setAlternativeManager(alg.getAlternativeManager());
                 // Add areas now!
                 addAreas(new KnuthPossPosIter(effectiveList,
                         startElementIndex, endElementIndex + 1), childLC);

Added: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/Alternative.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/Alternative.java?rev=1520134&view=auto
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/Alternative.java (added)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/Alternative.java Wed Sep  4 20:32:32 2013
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* $Id$ */
+
+package org.apache.fop.layoutmgr;
+
+import java.util.List;
+
+public class Alternative {
+
+    /** remaining BPD after inserting the alternative */
+    private int remainingBPD;
+    /** width of the alternative in block-progressing-dimension */
+    private final int width;
+    /** Knuth element list */
+    private final List<ListElement> knuthList;
+    /** Indicates whether we should consider the alternative or not */
+    private boolean enabled;
+
+    public Alternative(List<ListElement> knuthList, int width) {
+        this.knuthList = knuthList;
+        this.width = width;
+        this.remainingBPD = 0;
+        this.enabled = false;
+    }
+
+    public List<ListElement> getKnuthList() {
+        return knuthList;
+    }
+
+    public int getRemainingBPD() {
+        return remainingBPD;
+    }
+
+    public int getWidth() {
+        return width;
+    }
+
+    public void setRemainingBPD(int remainingBPD) {
+        this.remainingBPD = remainingBPD;
+    }
+
+    public void setEnabled(boolean enabled) {
+        this.enabled = enabled;
+    }
+
+    public boolean isEnabled() {
+        return enabled;
+    }
+
+    public static enum FittingStrategy {
+
+        FIRST_FIT("first-fit") {
+
+            @Override
+            public Alternative filter(List<Alternative> alternatives) {
+                for (Alternative alt : alternatives) {
+                    if (alt.isEnabled()) {
+                        return alt;
+                    }
+                }
+                return null;
+            }
+        },
+
+        SMALLEST_FIT("smallest-fit") {
+
+            @Override
+            public Alternative filter(List<Alternative> alternatives) {
+                int biggestDiff = -Integer.MAX_VALUE;
+                Alternative bestAlt = null;
+
+                for (Alternative alt : alternatives) {
+                    if (alt.isEnabled() && alt.getRemainingBPD() > biggestDiff) {
+                        biggestDiff = alt.getRemainingBPD();
+                        bestAlt = alt;
+                    }
+                }
+                return bestAlt;
+            }
+        },
+
+        BIGGEST_FIT("biggest-fit") {
+
+            @Override
+            public Alternative filter(List<Alternative> alternatives) {
+                int smallestDiff = Integer.MAX_VALUE;
+                Alternative bestAlt = null;
+
+                for (Alternative alt : alternatives) {
+                    if (alt.isEnabled() && alt.getRemainingBPD() < smallestDiff) {
+                        smallestDiff = alt.getRemainingBPD();
+                        bestAlt = alt;
+                    }
+                }
+                return bestAlt;
+            }
+        };
+
+        private String strategyName;
+
+        FittingStrategy(String strategyName) {
+            this.strategyName = strategyName;
+        }
+
+        public String getStrategyName() {
+            return strategyName;
+        }
+
+        /**
+         * @param alternatives the list of potential candidate {@link Alternative}
+         * @return the best alternative according to the strategy being employed
+         */
+        public abstract Alternative filter(List<Alternative> alternatives);
+
+    }
+}

Propchange: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/Alternative.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/Alternative.java
------------------------------------------------------------------------------
    svn:keywords = Revision Id

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/AlternativeBlockLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/AlternativeBlockLayoutManager.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/AlternativeBlockLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/AlternativeBlockLayoutManager.java Wed Sep  4 20:32:32 2013
@@ -64,24 +64,25 @@ public class AlternativeBlockLayoutManag
     }
 
     /** {@inheritDoc} */
+    @Override
     public List getNextKnuthElements(LayoutContext context, int alignment,
             Stack lmStack, Position positionAtIPDChange,
             LayoutManager restartAtLM) {
         LayoutManager curLM;
-        List<ListElement> returnList = new LinkedList<ListElement>();
+        List<ListElement> knuthList = new LinkedList<ListElement>();
         while ((curLM = getChildLM()) != null) {
             LayoutContext childLC = makeChildLayoutContext(context);
 
-            List returnedList = null;
+            List childKnuthList = null;
             if (!curLM.isFinished()) {
-                returnedList = curLM.getNextKnuthElements(childLC, alignment);
+                childKnuthList = curLM.getNextKnuthElements(childLC, alignment);
             }
-            if (returnedList != null) {
-                wrapPositionElements(returnedList, returnList);
+            if (childKnuthList != null) {
+                wrapPositionElements(childKnuthList, knuthList);
             }
         }
         setFinished(true);
-        return returnList;
+        return knuthList;
     }
 
     /**
@@ -232,6 +233,7 @@ public class AlternativeBlockLayoutManag
     }
 
     /** {@inheritDoc} */
+    @Override
     public boolean isRestartable() {
         return true;
     }

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutManager.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitLayoutManager.java Wed Sep  4 20:32:32 2013
@@ -29,8 +29,7 @@ import org.apache.fop.area.Area;
 import org.apache.fop.area.Block;
 import org.apache.fop.area.LineArea;
 import org.apache.fop.fo.extensions.BestFit;
-import org.apache.fop.layoutmgr.AlternativeManager.Alternative;
-import org.apache.fop.layoutmgr.AlternativeManager.FittingStrategy;
+import org.apache.fop.layoutmgr.Alternative.FittingStrategy;
 
 /**
  * LayoutManager for a fox:best-fit. It selects the "best" alternative
@@ -39,6 +38,7 @@ import org.apache.fop.layoutmgr.Alternat
 public class BestFitLayoutManager extends AbstractLayoutManager {
 
     private Block curBlockArea;
+    private BestFitPenalty bestFitPenalty;
 
     private static class BestFitPosition extends Position {
 
@@ -48,7 +48,7 @@ public class BestFitLayoutManager extend
 
     }
 
-    private FittingStrategy fittingStrategy;
+    private final FittingStrategy fittingStrategy;
 
     public BestFitLayoutManager(BestFit node) {
         super(node);
@@ -78,32 +78,36 @@ public class BestFitLayoutManager extend
     }
 
     /** {@inheritDoc} */
+    @Override
     public List getNextKnuthElements(LayoutContext context, int alignment,
             Stack lmStack, Position positionAtIPDChange,
             LayoutManager restartAtLM) {
         LayoutManager curLM; // currently active LM
-        BestFitPenalty bestFitPenalty =
-                new BestFitPenalty(fittingStrategy, new BestFitPosition(this));
+        bestFitPenalty = new BestFitPenalty(fittingStrategy, new BestFitPosition(this));
         while ((curLM = getChildLM()) != null) {
             LayoutContext childLC = makeChildLayoutContext(context);
 
-            List returnedList = null;
+            List childKnuthList = null;
             if (!curLM.isFinished()) {
-                returnedList = curLM.getNextKnuthElements(childLC, alignment);
+                childKnuthList = curLM.getNextKnuthElements(childLC, alignment);
             }
-            if (returnedList != null) {
-                List<ListElement> returnList = new LinkedList<ListElement>();
-                this.wrapPositionElements(returnedList, returnList);
-                int contentLength = ElementListUtils.calcFullContentLength(returnList);
+            if (childKnuthList != null) {
+                List<ListElement> newKnuthList = new LinkedList<ListElement>();
+                this.wrapPositionElements(childKnuthList, newKnuthList);
+                int contentLength = ElementListUtils.calcFullContentLength(newKnuthList);
                 // Add a new variant
-                bestFitPenalty.addAlternative(new Alternative(returnList, contentLength));
+                bestFitPenalty.addAlternative(new Alternative(newKnuthList, contentLength));
             }
         }
         setFinished(true);
         List<ListElement> finalList = new LinkedList<ListElement>();
-        // Insert an empty Knuth box to prevent the layout engine from ignoring our penalty
+        // Enclose the penalty with two empty Knuth boxes
+        // to prevent the layout engine from ignoring it.
+        // I know this seems like a hack, but I'll address
+        // this issue properly when more tests are done
         finalList.add(new KnuthBox(0, new Position(this), false));
         finalList.add(bestFitPenalty);
+        finalList.add(new KnuthBox(0, new Position(this), false));
         return finalList;
     }
 
@@ -213,7 +217,6 @@ public class BestFitLayoutManager extend
         // and put them in a new list;
         LinkedList<Position> positionList = new LinkedList<Position>();
         Position pos;
-        AlternativeManager altManager = layoutContext.getAlternativeManager();
         while (parentIter.hasNext()) {
             pos = parentIter.next();
             if (pos.getIndex() >= 0) {
@@ -230,10 +233,9 @@ public class BestFitLayoutManager extend
                 if (firstLM == null) {
                     firstLM = lastLM;
                 }
-            }
-            else if (pos instanceof BestFitPosition) {
-                if (altManager.hasAny()) {
-                    Alternative bestAlt = altManager.getNextBestAlternative();
+            } else if (pos instanceof BestFitPosition) {
+                if (bestFitPenalty.getBestAlternative() != null) {
+                    Alternative bestAlt = bestFitPenalty.getBestAlternative();
                     Iterator<ListElement> it = bestAlt.getKnuthList().iterator();
                     while (it.hasNext()) {
                         positionList.add(it.next().getPosition());
@@ -270,6 +272,7 @@ public class BestFitLayoutManager extend
     }
 
     /** {@inheritDoc} */
+    @Override
     public boolean isRestartable() {
         return true;
     }

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BestFitPenalty.java Wed Sep  4 20:32:32 2013
@@ -20,9 +20,9 @@
 package org.apache.fop.layoutmgr;
 
 import java.util.LinkedList;
+import java.util.List;
 
-import org.apache.fop.layoutmgr.AlternativeManager.Alternative;
-import org.apache.fop.layoutmgr.AlternativeManager.FittingStrategy;
+import org.apache.fop.layoutmgr.Alternative.FittingStrategy;
 
 /**
  * A dummy penalty used in {@link BestFitLayoutManager} to store
@@ -31,8 +31,9 @@ import org.apache.fop.layoutmgr.Alternat
 
 public class BestFitPenalty extends KnuthPenalty {
 
-    private LinkedList<Alternative> alternatives;
-    private FittingStrategy strategy;
+    private final LinkedList<Alternative> alternatives;
+    private final FittingStrategy strategy;
+    private Alternative bestAlternative = null;
 
     public BestFitPenalty(FittingStrategy strategy, Position pos) {
         super(0, 0, false, pos, false);
@@ -44,23 +45,33 @@ public class BestFitPenalty extends Knut
         alternatives.add(alternative);
     }
 
-    public Alternative getAlternative(int index) {
-        return alternatives.get(index);
-    }
-
-    public int getAlternativeCount() {
-        return alternatives.size();
+    public List<Alternative> getAlternatives() {
+        return alternatives;
     }
 
     public FittingStrategy getStrategyType() {
         return strategy;
     }
 
+    public Alternative getBestAlternative() {
+        if (bestAlternative != null) {
+            return bestAlternative;
+        } else {
+            bestAlternative = strategy.filter(alternatives);
+            return bestAlternative;
+        }
+    }
+
+//    public void setBestAlternative(Alternative bestAlternative) {
+//        this.bestAlternative = bestAlternative;
+//    }
+
     /** {@inheritDoc} */
+    @Override
     public String toString() {
         String str = super.toString();
         StringBuffer buffer = new StringBuffer(64);
-        buffer.append(" number of alternatives = " + getAlternativeCount());
+        buffer.append(" number of alternatives = " + getAlternatives().size());
         buffer.append(" fitting-strategy = " + strategy);
         return str + buffer.toString();
     }

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/BreakingAlgorithm.java Wed Sep  4 20:32:32 2013
@@ -23,7 +23,6 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 import org.apache.fop.fo.Constants;
-import org.apache.fop.layoutmgr.AlternativeManager.Alternative;
 
 /**
  * The set of nodes is sorted into lines indexed into activeLines.
@@ -193,8 +192,6 @@ public abstract class BreakingAlgorithm 
     private boolean partOverflowRecoveryActivated = true;
     private KnuthNode lastRecovered;
 
-    private AlternativeManager altManager = new AlternativeManager();
-
     /**
      * Create a new instance.
      *
@@ -307,6 +304,7 @@ public abstract class BreakingAlgorithm 
         }
 
         /** {@inheritDoc} */
+        @Override
         public String toString() {
             return "<KnuthNode at " + position + " "
                     + totalWidth + "+" + totalStretch + "-" + totalShrink
@@ -322,12 +320,12 @@ public abstract class BreakingAlgorithm 
     protected class BestRecords {
         private static final double INFINITE_DEMERITS = Double.POSITIVE_INFINITY;
 
-        private double[] bestDemerits = new double[4];
-        private KnuthNode[] bestNode = new KnuthNode[4];
-        private double[] bestAdjust = new double[4];
-        private int[] bestDifference = new int[4];
-        private int[] bestAvailableShrink = new int[4];
-        private int[] bestAvailableStretch = new int[4];
+        private final double[] bestDemerits = new double[4];
+        private final KnuthNode[] bestNode = new KnuthNode[4];
+        private final double[] bestAdjust = new double[4];
+        private final int[] bestDifference = new int[4];
+        private final int[] bestAvailableShrink = new int[4];
+        private final int[] bestAvailableStretch = new int[4];
         /** Points to the fitness class which currently leads to the best demerits. */
         private int bestIndex = -1;
 
@@ -825,30 +823,6 @@ public abstract class BreakingAlgorithm 
         }
     }
 
-    private int handleBestFitPenalty(BestFitPenalty penalty, KnuthNode node,
-            int elementIdx) {
-        int difference;
-        // Find the alternatives that can be fitted inside the remaining space
-        for (int i = 0; i < penalty.getAlternativeCount(); ++i) {
-            Alternative alt = penalty.getAlternative(i);
-            difference = computeDifference(node, new KnuthPenalty(alt.getWidth(),
-                    0, false, null, false), elementIdx);
-            if (difference > 0) {
-                alt.setRemainingBPD(difference);
-                altManager.addAlternative(alt);
-            }
-        }
-        Alternative bestAlt = altManager.getBestAlternative(penalty.getStrategyType());
-        if (bestAlt != null) {
-            difference = bestAlt.getRemainingBPD();
-            return difference;
-        } else {
-            // No alternative can be fitted inside the remaining space
-            return computeDifference(node, new KnuthPenalty(0,
-                    0, false, null, false), elementIdx);
-        }
-    }
-
     /**
      * Replace the last too-long or too-short node by the last deactivated
      * node, if applicable.
@@ -1002,6 +976,33 @@ public abstract class BreakingAlgorithm 
         }
     }
 
+    private int handleBestFitPenalty(BestFitPenalty penalty, KnuthNode node,
+            int elementIdx) {
+        // Find the alternatives that can be fitted inside the remaining space
+        for (int i = 0; i < penalty.getAlternatives().size(); ++i) {
+            Alternative alt = penalty.getAlternatives().get(i);
+            int difference = computeDifference(node, new KnuthPenalty(alt.getWidth(),
+                    0, false, null, false), elementIdx);
+            double r = computeAdjustmentRatio(node, difference);
+            //if (r >= -1) {
+                alt.setRemainingBPD(difference);
+                alt.setEnabled(r >= -1);
+                //altManager.addAlternative(alt);
+            //}
+        }
+        Alternative bestAlt = penalty.getBestAlternative();
+        if (bestAlt != null) {
+            //penalty.setBestAlternative(bestAlt);
+            // Add an empty KnuthBox to represent the chosen alternative
+            par.add(elementIdx + 1, new KnuthBox(bestAlt.getWidth(), null, false));
+            return bestAlt.getRemainingBPD();
+        } else {
+            // No "good" alternative was found
+            return computeDifference(node, new KnuthPenalty(0,
+                    0, false, null, false), elementIdx);
+        }
+    }
+
     /**
      * Check if the given {@link KnuthElement} can end the line with the given
      * number.
@@ -1021,7 +1022,7 @@ public abstract class BreakingAlgorithm 
      * @param node  the node
      * @param line  the line number
      * @param elementIdx    the position index of the element
-     * @param difference    the difference between content-length and avaialable width
+     * @param difference    the difference between content-length and available width
      * @param r     the adjustment ratio
      * @param demerits  demerits produced by the node
      * @param fitnessClass  the fitness class
@@ -1484,9 +1485,4 @@ public abstract class BreakingAlgorithm 
         return this.alignmentLast;
     }
 
-    /** @return the alternative manager (used by fox:best-fit) */
-    public AlternativeManager getAlternativeManager() {
-        return altManager;
-    }
-
 }

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/ElementListUtils.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/ElementListUtils.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/ElementListUtils.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/ElementListUtils.java Wed Sep  4 20:32:32 2013
@@ -178,12 +178,12 @@ public final class ElementListUtils {
                 len += ((KnuthElement)el).getWidth();
             } else if (el.isGlue()) {
                 len += ((KnuthElement)el).getWidth();
-            }
-            else if (el.isUnresolvedElement() && (el instanceof BreakElement) == false) {
+            } else if (el.isUnresolvedElement() && !(el instanceof BreakElement)) {
                 // Handle properties space-before and space-after
                 UnresolvedListElementWithLength uresolvedEl = (UnresolvedListElementWithLength)el;
-                if (uresolvedEl.isLast() || uresolvedEl.isFirst())
+                if (uresolvedEl.isLast() || uresolvedEl.isFirst()) {
                     len += uresolvedEl.getLength().getOpt();
+                }
             }
             count--;
             if (count == 0) {

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/FlowLayoutManager.java Wed Sep  4 20:32:32 2013
@@ -48,7 +48,7 @@ public class FlowLayoutManager extends B
     private static Log log = LogFactory.getLog(FlowLayoutManager.class);
 
     /** Array of areas currently being filled stored by area class */
-    private BlockParent[] currentAreas = new BlockParent[Area.CLASS_MAX];
+    private final BlockParent[] currentAreas = new BlockParent[Area.CLASS_MAX];
 
     /**
      * This is the top level layout manager.
@@ -204,7 +204,6 @@ public class FlowLayoutManager extends B
         childLC.setStackLimitBP(context.getStackLimitBP());
         childLC.setRefIPD(context.getRefIPD());
         childLC.setWritingMode(getCurrentPage().getSimplePageMaster().getWritingMode());
-        childLC.setAlternativeManager(context.getAlternativeManager());
         return childLC;
     }
 

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/LayoutContext.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/LayoutContext.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/LayoutContext.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/LayoutContext.java Wed Sep  4 20:32:32 2013
@@ -23,7 +23,6 @@ import java.util.Collections;
 import java.util.List;
 
 import org.apache.fop.fo.Constants;
-import org.apache.fop.fo.extensions.AlternativeBlock;
 import org.apache.fop.layoutmgr.inline.AlignmentContext;
 import org.apache.fop.layoutmgr.inline.HyphContext;
 import org.apache.fop.traits.MinOptMax;
@@ -36,9 +35,6 @@ import org.apache.fop.traits.WritingMode
  */
 public final class LayoutContext {
 
-    /** Manager of @{link {@link AlternativeBlock} and only used by {@link BestFitLayoutManager}*/
-    private AlternativeManager altManager;
-
     /** Generated break possibility is first in a new area */
     public static final int NEW_AREA = 0x01;
 
@@ -146,7 +142,6 @@ public final class LayoutContext {
     public static LayoutContext offspringOf(LayoutContext parent) {
         LayoutContext offspring = new LayoutContext(0);
         offspring.setTreatAsArtifact(parent.treatAsArtifact());
-        offspring.setAlternativeManager(parent.getAlternativeManager());
         return offspring;
     }
 
@@ -649,6 +644,7 @@ public final class LayoutContext {
     }
 
     /** {@inheritDoc} */
+    @Override
     public String toString() {
         return "Layout Context:"
                 + "\nStack Limit BPD: \t"
@@ -697,13 +693,5 @@ public final class LayoutContext {
     public void setTreatAsArtifact(boolean treatAsArtifact) {
         setFlags(TREAT_AS_ARTIFACT, treatAsArtifact);
     }
-
-    public void setAlternativeManager(AlternativeManager altManager) {
-        this.altManager = altManager;
-    }
-
-    public AlternativeManager getAlternativeManager() {
-        return altManager;
-    }
 }
 

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/src/java/org/apache/fop/layoutmgr/PageBreakingAlgorithm.java Wed Sep  4 20:32:32 2013
@@ -26,6 +26,7 @@ import java.util.ListIterator;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+
 import org.apache.fop.fo.Constants;
 import org.apache.fop.fo.FObj;
 import org.apache.fop.layoutmgr.AbstractBreaker.PageBreakPosition;
@@ -37,9 +38,9 @@ class PageBreakingAlgorithm extends Brea
     /** the logger for the class */
     private static Log log = LogFactory.getLog(PageBreakingAlgorithm.class);
 
-    private LayoutManager topLevelLM;
-    private PageProvider pageProvider;
-    private PageBreakingLayoutListener layoutListener;
+    private final LayoutManager topLevelLM;
+    private final PageProvider pageProvider;
+    private final PageBreakingLayoutListener layoutListener;
     /** List of PageBreakPosition elements. */
     private LinkedList<PageBreakPosition> pageBreaks = null;
 
@@ -72,9 +73,9 @@ class PageBreakingAlgorithm extends Brea
     private int footnoteElementIndex = -1;
 
     // demerits for a page break that splits a footnote
-    private int splitFootnoteDemerits = 5000;
+    private final int splitFootnoteDemerits = 5000;
     // demerits for a page break that defers a whole footnote to the following page
-    private int deferredFootnoteDemerits = 10000;
+    private final int deferredFootnoteDemerits = 10000;
     private MinOptMax footnoteSeparatorLength = null;
 
     // the method noBreakBetween(int, int) uses these variables
@@ -171,10 +172,11 @@ class PageBreakingAlgorithm extends Brea
      */
     protected class BestPageRecords extends BestRecords {
 
-        private int[] bestFootnotesLength = new int[4];
-        private int[] bestFootnoteListIndex = new int[4];
-        private int[] bestFootnoteElementIndex = new int[4];
+        private final int[] bestFootnotesLength = new int[4];
+        private final int[] bestFootnoteListIndex = new int[4];
+        private final int[] bestFootnoteElementIndex = new int[4];
 
+        @Override
         public void addRecord(double demerits, KnuthNode node, double adjust,
                               int availableShrink, int availableStretch,
                               int difference, int fitness) {

Modified: xmlgraphics/fop/branches/Temp_WhitespaceManagement/test/java/org/apache/fop/KnuthAlgorithmTestCase.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/branches/Temp_WhitespaceManagement/test/java/org/apache/fop/KnuthAlgorithmTestCase.java?rev=1520134&r1=1520133&r2=1520134&view=diff
==============================================================================
--- xmlgraphics/fop/branches/Temp_WhitespaceManagement/test/java/org/apache/fop/KnuthAlgorithmTestCase.java (original)
+++ xmlgraphics/fop/branches/Temp_WhitespaceManagement/test/java/org/apache/fop/KnuthAlgorithmTestCase.java Wed Sep  4 20:32:32 2013
@@ -19,15 +19,12 @@
 
 package org.apache.fop;
 
-import java.util.List;
-
-import org.junit.Before;
-import org.junit.Test;
-
 import static org.junit.Assert.assertEquals;
 
-import org.apache.fop.layoutmgr.AlternativeManager.Alternative;
-import org.apache.fop.layoutmgr.AlternativeManager.FittingStrategy;
+import java.util.List;
+
+import org.apache.fop.layoutmgr.Alternative;
+import org.apache.fop.layoutmgr.Alternative.FittingStrategy;
 import org.apache.fop.layoutmgr.BestFitPenalty;
 import org.apache.fop.layoutmgr.BlockKnuthSequence;
 import org.apache.fop.layoutmgr.BreakingAlgorithm;
@@ -36,6 +33,8 @@ import org.apache.fop.layoutmgr.KnuthBox
 import org.apache.fop.layoutmgr.KnuthGlue;
 import org.apache.fop.layoutmgr.KnuthPenalty;
 import org.apache.fop.layoutmgr.KnuthSequence;
+import org.junit.Before;
+import org.junit.Test;
 
 /**
  * Tests the Knuth algorithm implementation.
@@ -67,25 +66,21 @@ public class KnuthAlgorithmTestCase {
         return seq;
     }
 
-    private static class BestFitPenaltyTestCase {
-
-        private static KnuthSequence getKnuthSequence() {
-            KnuthSequence seq = new BlockKnuthSequence();
-            FittingStrategy strategies[] = {FittingStrategy.FIRST_FIT,
-                    FittingStrategy.SMALLEST_FIT,
-                    FittingStrategy.BIGGEST_FIT};
-            for (int i = 0; i < 3; ++i) {
-                BestFitPenalty bestFitPenalty = new BestFitPenalty(strategies[i], null);
-                bestFitPenalty.addAlternative(new Alternative(null, 25000));
-                bestFitPenalty.addAlternative(new Alternative(null, 5000));
-                bestFitPenalty.addAlternative(new Alternative(null, 29000));
-                seq.add(new KnuthBox(0, null, false));
-                seq.add(bestFitPenalty);
-                seq.add(new KnuthPenalty(0, -KnuthPenalty.INFINITE, false, null, false));
-            }
-            return seq;
+    private static KnuthSequence getKnuthSequence2() {
+        KnuthSequence seq = new BlockKnuthSequence();
+        FittingStrategy[] strategies = {FittingStrategy.FIRST_FIT,
+                FittingStrategy.SMALLEST_FIT,
+                FittingStrategy.BIGGEST_FIT};
+        for (int i = 0; i < 3; ++i) {
+            BestFitPenalty bestFitPenalty = new BestFitPenalty(strategies[i], null);
+            bestFitPenalty.addAlternative(new Alternative(null, 25000));
+            bestFitPenalty.addAlternative(new Alternative(null, 5000));
+            bestFitPenalty.addAlternative(new Alternative(null, 29000));
+            seq.add(new KnuthBox(0, null, false));
+            seq.add(bestFitPenalty);
+            seq.add(new KnuthPenalty(0, -KnuthPenalty.INFINITE, false, null, false));
         }
-
+        return seq;
     }
 
     /**
@@ -112,13 +107,13 @@ public class KnuthAlgorithmTestCase {
     public void test2() throws Exception {
         MyBreakingAlgorithm algo = new MyBreakingAlgorithm(0, 0, true, true, 0);
         algo.setConstantLineWidth(30000);
-        KnuthSequence seq = BestFitPenaltyTestCase.getKnuthSequence();
+        KnuthSequence seq = getKnuthSequence2();
         algo.findBreakingPoints(seq, 1, true, BreakingAlgorithm.ALL_BREAKS);
         Part[] parts = algo.getParts();
         assertEquals("Sequence must produce 3 parts", 3, parts.length);
-        assertEquals(5000, 	parts[0].difference);
+        assertEquals(5000, parts[0].difference);
         assertEquals(25000, parts[1].difference);
-        assertEquals(1000, 	parts[2].difference);
+        assertEquals(1000, parts[2].difference);
     }
 
     private class Part {
@@ -129,7 +124,7 @@ public class KnuthAlgorithmTestCase {
 
     private class MyBreakingAlgorithm extends BreakingAlgorithm {
 
-        private List<Part> parts = new java.util.ArrayList<Part>();
+        private final List<Part> parts = new java.util.ArrayList<Part>();
 
         public MyBreakingAlgorithm(int align, int alignLast, boolean first,
                     boolean partOverflowRecovery, int maxFlagCount) {
@@ -140,10 +135,12 @@ public class KnuthAlgorithmTestCase {
             return parts.toArray(new Part[parts.size()]);
         }
 
+        @Override
         public void updateData1(int total, double demerits) {
             //nop
         }
 
+        @Override
         public void updateData2(KnuthNode bestActiveNode, KnuthSequence sequence, int total) {
             int difference = bestActiveNode.difference;
             // it is always allowed to adjust space, so the ratio must be set regardless of
@@ -177,6 +174,7 @@ public class KnuthAlgorithmTestCase {
             parts.add(0, part);
         }
 
+        @Override
         protected int filterActiveNodes() {
             //nop
             return 0;



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