Class BSPTreePrinter<P extends Point<P>,N extends BSPTree.Node<P,N>>
- java.lang.Object
-
- org.apache.commons.geometry.core.partitioning.bsp.BSPTreePrinter<P,N>
-
- Type Parameters:
P- Point implementation typeN- Node implementation type
- All Implemented Interfaces:
BSPTreeVisitor<P,N>
final class BSPTreePrinter<P extends Point<P>,N extends BSPTree.Node<P,N>> extends java.lang.Object implements BSPTreeVisitor<P,N>
Internal class for creating simple string representations of BSP trees.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.commons.geometry.core.partitioning.bsp.BSPTreeVisitor
BSPTreeVisitor.ClosestFirstVisitor<P extends Point<P>,N extends BSPTree.Node<P,N>>, BSPTreeVisitor.FarthestFirstVisitor<P extends Point<P>,N extends BSPTree.Node<P,N>>, BSPTreeVisitor.Order, BSPTreeVisitor.Result, BSPTreeVisitor.TargetPointVisitor<P extends Point<P>,N extends BSPTree.Node<P,N>>
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringELLIPSISEllipsis for truncated representations.private static java.lang.StringINDENTLine indent string.private intmaxDepthMaximum depth of nodes that will be printed.private static java.lang.StringMINUS_CHILDEntry prefix for nodes on the minus side of their parent.private static java.lang.StringNEW_LINENew line character.private java.lang.StringBuilderoutputContains the string output.private static java.lang.StringPLUS_CHILDEntry prefix for nodes on the plus side of their parent.
-
Constructor Summary
Constructors Constructor Description BSPTreePrinter(int maxDepth)Simple constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidstartLine(N node)Start a line for the given node.java.lang.StringtoString()Return the string representation of the visited tree.BSPTreeVisitor.Resultvisit(N node)Visit a node in a BSP tree.BSPTreeVisitor.OrdervisitOrder(N node)Determine the visit order for the given internal node.private voidwrite(java.lang.String str)Add the given string to the output.private voidwriteNode(N node)Writes the given node to the output.
-
-
-
Field Detail
-
INDENT
private static final java.lang.String INDENT
Line indent string.- See Also:
- Constant Field Values
-
NEW_LINE
private static final java.lang.String NEW_LINE
New line character.- See Also:
- Constant Field Values
-
MINUS_CHILD
private static final java.lang.String MINUS_CHILD
Entry prefix for nodes on the minus side of their parent.- See Also:
- Constant Field Values
-
PLUS_CHILD
private static final java.lang.String PLUS_CHILD
Entry prefix for nodes on the plus side of their parent.- See Also:
- Constant Field Values
-
ELLIPSIS
private static final java.lang.String ELLIPSIS
Ellipsis for truncated representations.- See Also:
- Constant Field Values
-
maxDepth
private final int maxDepth
Maximum depth of nodes that will be printed.
-
output
private final java.lang.StringBuilder output
Contains the string output.
-
-
Method Detail
-
visit
public BSPTreeVisitor.Result visit(N node)
Visit a node in a BSP tree. This method is called for both internal nodes and leaf nodes.- Specified by:
visitin interfaceBSPTreeVisitor<P extends Point<P>,N extends BSPTree.Node<P,N>>- Parameters:
node- the node being visited- Returns:
- the result of the visit operation
-
visitOrder
public BSPTreeVisitor.Order visitOrder(N node)
Determine the visit order for the given internal node. This is called for each internal node beforeBSPTreeVisitor.visit(BSPTree.Node)is called. Returning null orBSPTreeVisitor.Order.NONEfrom this method skips the subtree rooted at the given node. This method is not called on leaf nodes.- Specified by:
visitOrderin interfaceBSPTreeVisitor<P extends Point<P>,N extends BSPTree.Node<P,N>>- Parameters:
node- the internal node to determine the visit order for- Returns:
- the order that the subtree rooted at the given node should be visited
-
startLine
private void startLine(N node)
Start a line for the given node.- Parameters:
node- the node to begin a line for
-
writeNode
private void writeNode(N node)
Writes the given node to the output.- Parameters:
node- the node to write
-
write
private void write(java.lang.String str)
Add the given string to the output.- Parameters:
str- the string to add
-
toString
public java.lang.String toString()
Return the string representation of the visited tree.- Overrides:
toStringin classjava.lang.Object
-
-