[FOray-commit] SF.net SVN: foray:[12186] trunk/foray
Modular XSL-FO Implementation for Java.
Status: Alpha
Brought to you by:
victormote
|
From: <vic...@us...> - 2021-12-07 18:26:01
|
Revision: 12186
http://sourceforge.net/p/foray/code/12186
Author: victormote
Date: 2021-12-07 18:25:59 +0000 (Tue, 07 Dec 2021)
Log Message:
-----------
Minor improvements to tree structures.
Modified Paths:
--------------
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaFlexible.java
trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractOrderedTreeNode.java
trunk/foray/foray-common/src/main/java/org/foray/common/data/OrderedTreeNode.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Marker4a.java
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaFlexible.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaFlexible.java 2021-12-07 17:35:05 UTC (rev 12185)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaFlexible.java 2021-12-07 18:25:59 UTC (rev 12186)
@@ -28,6 +28,7 @@
package org.foray.area;
+import org.foray.common.data.AbstractOrderedTreeNode;
import org.foray.common.data.OrderedTreeNode;
import org.axsl.common.value.RelativeAxis;
@@ -205,7 +206,7 @@
if (previous == null) {
/* It is possible that the child area has not yet been registered
* with the parent Area yet. Use the last child of the parent. */
- final List<? extends OrderedTreeNode<AreaNode4a>> siblings = this.getSiblings();
+ final List<? extends AbstractOrderedTreeNode<AreaNode4a>> siblings = this.getSiblings();
if (siblings != null
&& siblings.size() > 0) {
final int lastIndex = siblings.size() - 1;
Modified: trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java
===================================================================
--- trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java 2021-12-07 17:35:05 UTC (rev 12185)
+++ trunk/foray/foray-areatree/src/main/java/org/foray/area/AreaNode4a.java 2021-12-07 18:25:59 UTC (rev 12186)
@@ -29,7 +29,6 @@
package org.foray.area;
import org.foray.common.data.AbstractOrderedTreeNode;
-import org.foray.common.data.OrderedTreeNode;
import org.axsl.area.AreaNode;
import org.axsl.area.AreaTreeException;
@@ -52,7 +51,7 @@
* Abstract superclass for all nodes in the AreaTree.
*/
public abstract class AreaNode4a extends AbstractOrderedTreeNode<AreaNode4a>
- implements AreaNode, OrderedTreeNode.Convertible<AreaNode4a> {
+ implements AreaNode, AbstractOrderedTreeNode.Convertible<AreaNode4a> {
/**
* Constructor.
@@ -79,7 +78,7 @@
* Casts a native type item as an ordered tree node.
* @return The {@code nativeTypeInstance} cast as an ordered tree node.
*/
- public OrderedTreeNode<AreaNode4a> asOrderedNode() {
+ public AbstractOrderedTreeNode<AreaNode4a> asOrderedNode() {
return this;
}
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractOrderedTreeNode.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractOrderedTreeNode.java 2021-12-07 17:35:05 UTC (rev 12185)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/AbstractOrderedTreeNode.java 2021-12-07 18:25:59 UTC (rev 12186)
@@ -40,12 +40,40 @@
* Many of the methods in this class were liberated from that class.</p>
* @param <T> The type of node.
*/
-public abstract class AbstractOrderedTreeNode<T extends OrderedTreeNode.Convertible<T>>
- implements OrderedTreeNode<T> {
+public abstract class AbstractOrderedTreeNode<T> implements OrderedTreeNode<T> {
- @Override
- public OrderedTreeNode<T> getParentAsOrderedNode() {
- final T parent = getParent();
+ /**
+ * Interface for types that are can convert a native type to an ordered tree node.
+ * @param <T> The type of node.
+ */
+ public interface Convertible<T> {
+
+ /**
+ * Casts a native type item as an ordered tree node.
+ * @return The {@code nativeTypeInstance} cast as an ordered tree node.
+ */
+ AbstractOrderedTreeNode<T> asOrderedNode();
+
+ }
+
+ /**
+ * Casts the node as its native type.
+ * @return This, cast as its native type.
+ */
+ public abstract T asNativeType();
+
+ /**
+ * Returns the parent of this.
+ * @return The parent node.
+ */
+ public abstract AbstractOrderedTreeNode.Convertible<T> getParent();
+
+ /**
+ * Returns the parent of this, cast as an ordered tree node.
+ * @return The parent node.
+ */
+ public AbstractOrderedTreeNode<T> getParentAsOrderedNode() {
+ final AbstractOrderedTreeNode.Convertible<T> parent = getParent();
if (parent == null) {
return null;
}
@@ -53,6 +81,12 @@
}
/**
+ * Return the List of this node's children.
+ * @return The List of this node's children.
+ */
+ public abstract List<? extends AbstractOrderedTreeNode<T>> getChildren();
+
+ /**
* Returns an iterator that will iterate the descendant nodes of this node
* in post-traversal (depth-first) order.
* @return A post-traversal iterator of this node's descendants.
@@ -89,8 +123,8 @@
* Returns the List of this node's parent's children, which includes this node.
* @return The List of this node's parent's children.
*/
- public List<? extends OrderedTreeNode<T>> getSiblings() {
- final OrderedTreeNode<T> parent = getParentAsOrderedNode();
+ public List<? extends AbstractOrderedTreeNode<T>> getSiblings() {
+ final AbstractOrderedTreeNode<T> parent = getParentAsOrderedNode();
if (this.getParent() == null) {
return null;
}
@@ -251,7 +285,7 @@
if (anotherNode == null) {
return false;
}
- OrderedTreeNode<T> ancestor = this;
+ AbstractOrderedTreeNode<T> ancestor = this;
do {
if (ancestor == anotherNode) {
return true;
@@ -291,7 +325,7 @@
* @return nearest ancestor common to this node and {@code aNode},
* or null if none
*/
- public OrderedTreeNode<T> getSharedAncestor(final OrderedTreeNode<T> aNode) {
+ public OrderedTreeNode<T> getSharedAncestor(final AbstractOrderedTreeNode<T> aNode) {
if (aNode == this) {
return this;
} else if (aNode == null) {
@@ -301,8 +335,8 @@
final int level1;
final int level2;
int diff;
- OrderedTreeNode<T> node1;
- OrderedTreeNode<T> node2;
+ AbstractOrderedTreeNode<T> node1;
+ AbstractOrderedTreeNode<T> node2;
level1 = getLevel();
level2 = aNode.getLevel();
@@ -349,7 +383,7 @@
public int getLevel() {
int levels = 0;
OrderedTreeNode<T> ancestor = this;
- while ((ancestor = ancestor.getParent().asOrderedNode()) != null) {
+ while ((ancestor = ancestor.getParentAsOrderedNode()) != null) {
levels++;
}
return levels;
Modified: trunk/foray/foray-common/src/main/java/org/foray/common/data/OrderedTreeNode.java
===================================================================
--- trunk/foray/foray-common/src/main/java/org/foray/common/data/OrderedTreeNode.java 2021-12-07 17:35:05 UTC (rev 12185)
+++ trunk/foray/foray-common/src/main/java/org/foray/common/data/OrderedTreeNode.java 2021-12-07 18:25:59 UTC (rev 12186)
@@ -28,8 +28,6 @@
package org.foray.common.data;
-import java.util.List;
-
/**
* A tree node that is generic and aware of its relationships not only to its parents and children, but also to its
* siblings.
@@ -41,32 +39,6 @@
public interface OrderedTreeNode<T> {
/**
- * Interface for types that are can convert a native type to an ordered tree node.
- * @param <T> The type of node.
- */
- public interface Convertible<T> {
-
- /**
- * Casts a native type item as an ordered tree node.
- * @return The {@code nativeTypeInstance} cast as an ordered tree node.
- */
- OrderedTreeNode<T> asOrderedNode();
-
- }
-
- /**
- * Casts the node as its native type.
- * @return This, cast as its native type.
- */
- T asNativeType();
-
- /**
- * Returns the parent of this.
- * @return The parent node.
- */
- T getParent();
-
- /**
* Returns the parent of this, cast as an ordered tree node.
* @return The parent node.
*/
@@ -73,12 +45,6 @@
OrderedTreeNode<T> getParentAsOrderedNode();
/**
- * Return the List of this node's children.
- * @return The List of this node's children.
- */
- List<? extends OrderedTreeNode<T>> getChildren();
-
- /**
* Returns the number of children this contains.
* @return The number of children.
*/
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2021-12-07 17:35:05 UTC (rev 12185)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/FoObj.java 2021-12-07 18:25:59 UTC (rev 12186)
@@ -32,7 +32,6 @@
import org.foray.common.FontUtil;
import org.foray.common.WellKnownConstants;
import org.foray.common.data.AbstractOrderedTreeNode;
-import org.foray.common.data.OrderedTreeNode;
import org.foray.common.i18n.Country4a;
import org.foray.common.i18n.Language4a;
import org.foray.common.i18n.Script4a;
@@ -154,12 +153,10 @@
* Base class for formatting objects.
*/
public abstract class FoObj extends AbstractOrderedTreeNode<FoObj>
- implements Fo, ParaConfig, OrderedTreeNode.Convertible<FoObj> {
+ implements Fo, ParaConfig, AbstractOrderedTreeNode.Convertible<FoObj> {
- /** A static empty and immutable list of children, suitable for return by
- * objects that have no children. */
- protected static final List<FoObj> EMPTY_CHILD_LIST =
- Collections.emptyList();
+ /** A static empty and immutable list of children, suitable for return by objects that have no children. */
+ protected static final List<FoObj> EMPTY_CHILD_LIST = Collections.emptyList();
/** Static CharSequence containing one space, to be used for obtaining a font
* for the page-citation-* objects. */
@@ -199,7 +196,7 @@
}
@Override
- public OrderedTreeNode<FoObj> asOrderedNode() {
+ public AbstractOrderedTreeNode<FoObj> asOrderedNode() {
return this;
}
Modified: trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Marker4a.java
===================================================================
--- trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Marker4a.java 2021-12-07 17:35:05 UTC (rev 12185)
+++ trunk/foray/foray-fotree/src/main/java/org/foray/fotree/fo/obj/Marker4a.java 2021-12-07 18:25:59 UTC (rev 12186)
@@ -28,6 +28,7 @@
package org.foray.fotree.fo.obj;
+import org.foray.common.data.AbstractOrderedTreeNode;
import org.foray.common.data.OrderedTreeNode;
import org.foray.fotree.FoObj;
import org.foray.fotree.FoObjMixed;
@@ -74,7 +75,7 @@
throwException(getFullName() + " must be descendant of fo:flow.");
}
// Validate that there is not content before this and other markers.
- final List<? extends OrderedTreeNode<FoObj>> siblings = this.getSiblings();
+ final List<? extends AbstractOrderedTreeNode<FoObj>> siblings = getSiblings();
for (int i = 0; i < siblings.size(); i++) {
final FoObj sibling = siblings.get(i).asNativeType();
if (sibling instanceof Marker4a) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|