Skip to content

Commit

Permalink
Add generics to layout
Browse files Browse the repository at this point in the history
  • Loading branch information
simonsteiner1984 committed Jun 26, 2024
1 parent ca1d532 commit 3d750f3
Show file tree
Hide file tree
Showing 33 changed files with 86 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public boolean isRestartable() {
}

/** {@inheritDoc} */
public List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack,
public List<ListElement> getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack,
Position positionAtIPDChange, LayoutManager restartAtLM) {
throw new UnsupportedOperationException("Not implemented");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ protected PageBreakingAlgorithm.PageBreakingLayoutListener createLayoutListener(
* @param alignment the desired text alignment
* @return the list of KnuthElements
*/
protected abstract List<KnuthElement> getNextKnuthElements(LayoutContext context,
protected abstract List<ListElement> getNextKnuthElements(LayoutContext context,
int alignment);

/**
Expand All @@ -302,7 +302,7 @@ protected abstract List<KnuthElement> getNextKnuthElements(LayoutContext context
* change occurs between two LMs
* @return the list of KnuthElements
*/
protected List<KnuthElement> getNextKnuthElements(LayoutContext context, int alignment,
protected List<ListElement> getNextKnuthElements(LayoutContext context, int alignment,
Position positionAtIPDChange, LayoutManager restartAtLM) {
throw new UnsupportedOperationException("TODO: implement acceptable fallback");
}
Expand Down Expand Up @@ -673,13 +673,13 @@ protected int getNextBlockList(LayoutContext childLC, int nextSequenceStartsOn)
*/
protected int getNextBlockList(LayoutContext childLC, int nextSequenceStartsOn,
Position positionAtIPDChange, LayoutManager restartAtLM,
List<KnuthElement> firstElements) {
List<ListElement> firstElements) {
updateLayoutContext(childLC);
//Make sure the span change signal is reset
childLC.signalSpanChange(Constants.NOT_SET);

BlockSequence blockList;
List<KnuthElement> returnedList;
List<ListElement> returnedList;
if (firstElements == null) {
returnedList = getNextKnuthElements(childLC, alignment);
} else if (positionAtIPDChange == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public List getNextKnuthElements(LayoutContext context, int alignment) {
}

/** {@inheritDoc} */
public List getChangedKnuthElements(List oldList, int alignment) {
public List<ListElement> getChangedKnuthElements(List<ListElement> oldList, int alignment) {
log.warn("null implementation of getChangeKnuthElement() called!");
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ private List<ColumnContent> getInitialBreaks(int startIndex, int averageColLengt
boolean prevIsBox = false;
int colNumber = 1;
for (int i = startIndex; i < par.size(); i++) {
KnuthElement element = (KnuthElement) par.get(i);
KnuthElement element = par.get(i);
if (isLegalBreak(i, prevIsBox)) {
int breakLength = totalLength
+ (element instanceof KnuthPenalty ? element.getWidth() : 0);
Expand Down Expand Up @@ -225,7 +225,7 @@ private List<ColumnContent> sortElementsForBreaks(List<ColumnContent> breaks) {
}

private boolean isLegalBreak(int index, boolean prevIsBox) {
KnuthElement element = (KnuthElement) par.get(index);
KnuthElement element = par.get(index);
return element instanceof KnuthPenalty && element.getPenalty() < KnuthPenalty.INFINITE
|| prevIsBox && element instanceof KnuthGlue;
}
Expand All @@ -235,7 +235,7 @@ private int calcContentLength(KnuthSequence par, int startIndex, int endIndex) {
}

private int getPenaltyWidth(int index) {
KnuthElement element = (KnuthElement) par.get(index);
KnuthElement element = par.get(index);
return element instanceof KnuthPenalty ? element.getWidth() : 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public BlockKnuthSequence() {
* Creates a new list from an existing list.
* @param list The list from which to create the new list.
*/
public BlockKnuthSequence(List list) {
public BlockKnuthSequence(List<KnuthSequence> list) {
super(list);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static int computeFitness(double adjustRatio) {
/**
* The paragraph of KnuthElements.
*/
protected KnuthSequence par;
protected KnuthSequence<KnuthElement> par;

/**
* The width of a line (or height of a column in page-breaking mode).
Expand Down Expand Up @@ -1313,7 +1313,7 @@ protected void finish() {
* @return the element at index idx in the paragraph.
*/
protected KnuthElement getElement(int idx) {
return (KnuthElement) par.get(idx);
return par.get(idx);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class FootnoteBodyLayoutManager extends BlockStackingLayoutManager {

private List<KnuthElement> knuthElements;
private List<ListElement> knuthElements;

/**
* Creates a new FootnoteBodyLayoutManager.
Expand All @@ -41,7 +41,7 @@ public FootnoteBodyLayoutManager(FootnoteBody body) {
}

@Override
public List<KnuthElement> getNextKnuthElements(LayoutContext context, int alignment) {
public List getNextKnuthElements(LayoutContext context, int alignment) {
if (knuthElements == null) {
knuthElements = super.getNextKnuthElements(context, alignment);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* Represents a list of inline Knuth elements.
* If closed, it represents all elements of a Knuth paragraph.
*/
public class InlineKnuthSequence extends KnuthSequence {
public class InlineKnuthSequence<T extends ListElement> extends KnuthSequence {

private static final long serialVersionUID = 1354774188859946549L;

Expand All @@ -47,7 +47,7 @@ public InlineKnuthSequence() {
* Creates a new list from an existing list.
* @param list The list from which to create the new list.
*/
public InlineKnuthSequence(List list) {
public InlineKnuthSequence(List<T> list) {
super(list);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
/**
* Represents a list of {@link KnuthElement Knuth elements}.
*/
public abstract class KnuthSequence extends ArrayList {
public abstract class KnuthSequence<T extends ListElement> extends ArrayList<T> {

//TODO: do not extend ArrayList

Expand All @@ -44,7 +44,7 @@ public KnuthSequence() {
* Creates a new list from an existing list.
* @param list The list from which to create the new list.
*/
public KnuthSequence(List list) {
public KnuthSequence(List<T> list) {
super(list);
}

Expand Down Expand Up @@ -157,7 +157,7 @@ public ListElement removeLast() {
public ListElement getElement(int index) {
return (index >= size() || index < 0)
? null
: (ListElement) get(index);
: get(index);
}

/**
Expand All @@ -175,7 +175,7 @@ protected int getFirstBoxIndex(int startIndex) {
} else {
int boxIndex = startIndex;
@SuppressWarnings("unchecked")
Iterator<ListElement> iter = listIterator(startIndex);
Iterator<T> iter = listIterator(startIndex);
while (iter.hasNext() && !iter.next().isBox()) {
boxIndex++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public interface LayoutManager extends PercentBaseContext {
* @param alignment the desired text alignment
* @return the updated list of KnuthElements
*/
List getChangedKnuthElements(List oldList, int alignment);
List<ListElement> getChangedKnuthElements(List<ListElement> oldList, int alignment);

/**
* Whether the FO handled by this layout manager has a descendant (including itself)
Expand Down Expand Up @@ -269,7 +269,7 @@ public interface LayoutManager extends PercentBaseContext {
* a paragraph
* @return an updated list of elements, taking the new IPD into account
*/
List getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack,
List<ListElement> getNextKnuthElements(LayoutContext context, int alignment, Stack lmStack,
Position positionAtIPDChange, LayoutManager restartAtLM);

boolean isFromFootnote();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ protected LayoutContext createLayoutContext() {
return lc;
}

protected List getNextKnuthElements(LayoutContext context, int alignment) {
protected List<ListElement> getNextKnuthElements(LayoutContext context, int alignment) {
LayoutManager curLM; // currently active LM
List returnList = new LinkedList();
List<ListElement> returnList = new LinkedList<>();

while ((curLM = lm.getChildLM()) != null) {
LayoutContext childLC = LayoutContext.newInstance();
Expand Down
12 changes: 6 additions & 6 deletions fop-core/src/main/java/org/apache/fop/layoutmgr/PageBreaker.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,9 @@ private boolean containsFootnotes(List contentList, LayoutContext context) {
return containsFootnotes;
}

public static List<List<KnuthElement>> getFootnoteKnuthElements(FlowLayoutManager flowLM, LayoutContext context,
public static List<List<KnuthElement>> getFootnoteKnuthElements(FlowLayoutManager flowLM, LayoutContext context,
List<FootnoteBodyLayoutManager> footnoteBodyLMs) {
List<List<KnuthElement>> footnotes = new ArrayList<List<KnuthElement>>();
List<List<KnuthElement>> footnotes = new ArrayList<>();
LayoutContext footnoteContext = LayoutContext.copyOf(context);
footnoteContext.setStackLimitBP(context.getStackLimitBP());
footnoteContext.setRefIPD(flowLM.getPSLM()
Expand Down Expand Up @@ -245,8 +245,8 @@ private void handleFootnoteSeparator() {
}

/** {@inheritDoc} */
protected List getNextKnuthElements(LayoutContext context, int alignment) {
List contentList = null;
protected List<ListElement> getNextKnuthElements(LayoutContext context, int alignment) {
List<ListElement> contentList = null;

while (!childFLM.isFinished() && contentList == null) {
contentList = childFLM.getNextKnuthElements(context, alignment);
Expand All @@ -262,9 +262,9 @@ protected List getNextKnuthElements(LayoutContext context, int alignment) {
}

/** {@inheritDoc} */
protected List getNextKnuthElements(LayoutContext context, int alignment,
protected List<ListElement> getNextKnuthElements(LayoutContext context, int alignment,
Position positionAtIPDChange, LayoutManager restartAtLM) {
List contentList = null;
List<ListElement> contentList = null;

do {
contentList = childFLM.getNextKnuthElements(context, alignment, positionAtIPDChange,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public RetrieveTableMarkerLayoutManager(RetrieveTableMarker node) {
}

/** {@inheritDoc} */
public List getNextKnuthElements(LayoutContext context, int alignment) {
public List<KnuthSequence> getNextKnuthElements(LayoutContext context, int alignment) {
setFinished(true);
FONode foNode = (FONode) getFObj();
foNode = getTableLayoutManager().resolveRetrieveTableMarker((RetrieveTableMarker) foNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public StaticContentLayoutManager(PageSequenceLayoutManager pslm,
}

/** {@inheritDoc} */
public List getNextKnuthElements(LayoutContext context, int alignment) {
public List<ListElement> getNextKnuthElements(LayoutContext context, int alignment) {
throw new IllegalStateException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.fop.fo.FObj;
import org.apache.fop.fo.flow.AbstractGraphics;
import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
import org.apache.fop.layoutmgr.KnuthSequence;
import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.layoutmgr.TraitSetter;

Expand Down Expand Up @@ -111,8 +112,8 @@ private InlineViewport getInlineArea() {
}

/** {@inheritDoc} */
public List getNextKnuthElements(LayoutContext context,
int alignment) {
public List<KnuthSequence> getNextKnuthElements(LayoutContext context,
int alignment) {
InlineViewport areaCurrent = getInlineArea();
setCurrentArea(areaCurrent);
return super.getNextKnuthElements(context, alignment);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ protected InlineArea getEffectiveArea(LayoutContext layoutContext) {
}

/** {@inheritDoc} */
public List getNextKnuthElements(LayoutContext context, int alignment) {
public List<KnuthSequence> getNextKnuthElements(LayoutContext context, int alignment) {
Character fobj = (Character) this.fobj;

// TODO: may need some special handling for fo:character
Expand Down Expand Up @@ -152,7 +152,7 @@ public List getNextKnuthElements(LayoutContext context, int alignment) {

addKnuthElementsForBorderPaddingEnd(seq);

LinkedList<KnuthSequence> returnList = new LinkedList<KnuthSequence>();
LinkedList<KnuthSequence> returnList = new LinkedList<>();
returnList.add(seq);
setFinished(true);
return returnList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.apache.fop.layoutmgr.KnuthSequence;
import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.layoutmgr.LayoutManager;
import org.apache.fop.layoutmgr.ListElement;
import org.apache.fop.layoutmgr.PageSequenceLayoutManager;
import org.apache.fop.layoutmgr.Position;
import org.apache.fop.layoutmgr.PositionIterator;
Expand Down Expand Up @@ -129,8 +130,8 @@ private void fillArea(LayoutManager curLM) {

stackSize = 0;

List contentList = getNextKnuthElements(childLC, Constants.EN_START);
for (Object aContentList : contentList) {
List<ListElement> contentList = getNextKnuthElements(childLC, Constants.EN_START);
for (ListElement aContentList : contentList) {
KnuthElement element = (KnuthElement) aContentList;
if (element instanceof KnuthInlineBox) {
KnuthInlineBox box = (KnuthInlineBox) element;
Expand Down Expand Up @@ -315,12 +316,12 @@ public boolean applyChanges(List oldList, int depth) {
}

/** {@inheritDoc} */
public List getChangedKnuthElements(List oldList, int alignment) {
public List<ListElement> getChangedKnuthElements(List<ListElement> oldList, int alignment) {
return null;
}

/** {@inheritDoc} */
public List getChangedKnuthElements(List oldList, int alignment, int depth) {
public List<ListElement> getChangedKnuthElements(List<ListElement> oldList, int alignment, int depth) {
return getChangedKnuthElements(oldList, alignment);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import org.apache.fop.fo.flow.Float;
import org.apache.fop.layoutmgr.FloatContentLayoutManager;
import org.apache.fop.layoutmgr.InlineKnuthSequence;
import org.apache.fop.layoutmgr.KnuthElement;
import org.apache.fop.layoutmgr.KnuthPossPosIter;
import org.apache.fop.layoutmgr.KnuthSequence;
import org.apache.fop.layoutmgr.LayoutContext;
import org.apache.fop.layoutmgr.LayoutManager;
import org.apache.fop.layoutmgr.ListElement;
import org.apache.fop.layoutmgr.Position;
import org.apache.fop.layoutmgr.PositionIterator;
import org.apache.fop.layoutmgr.SpaceResolver;
Expand All @@ -38,7 +38,7 @@ public class FloatLayoutManager extends InlineStackingLayoutManager {

private FloatContentLayoutManager floatContentLM;
private KnuthInlineBox anchor;
private List<KnuthElement> floatContentKnuthElements;
private List<ListElement> floatContentKnuthElements;
private Float floatContent;
private boolean floatContentAreaAdded;

Expand All @@ -51,7 +51,7 @@ protected LayoutManager getChildLM() {
return null;
}

public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
public LinkedList<KnuthSequence> getNextKnuthElements(LayoutContext context, int alignment) {

if (!floatContentAreaAdded && !floatContent.isDisabled()) {
floatContentLM = new FloatContentLayoutManager(floatContent);
Expand All @@ -62,7 +62,7 @@ public LinkedList getNextKnuthElements(LayoutContext context, int alignment) {
}

// the only knuth element is a zero width and height knuth box
LinkedList knuthElements = new LinkedList();
LinkedList<KnuthSequence> knuthElements = new LinkedList<>();
KnuthSequence seq = new InlineKnuthSequence();
anchor = new KnuthInlineBox(0, null, null, true);
if (!floatContentAreaAdded) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public List getNextKnuthElements(LayoutContext context,
bodyLM.initialize();

// get Knuth elements representing the footnote citation
List returnedList = new LinkedList();
List<KnuthSequence> returnedList = new LinkedList<>();
while (!citationLM.isFinished()) {
List partialList = citationLM.getNextKnuthElements(context, alignment);
if (partialList != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ public boolean applyChanges(List oldList, int depth) {
return false;
}

public List getChangedKnuthElements(List oldList, int alignment, int depth) {
public List<ListElement> getChangedKnuthElements(List<ListElement> oldList, int alignment, int depth) {
return oldList;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private boolean mustKeepTogether(LayoutManager lm) {

/** {@inheritDoc} */
@Override
public List getNextKnuthElements(
public List<KnuthSequence> getNextKnuthElements(
LayoutContext context, int alignment) {
LayoutManager curLM;

Expand Down
Loading

0 comments on commit 3d750f3

Please sign in to comment.