/** * Tests the formatting as a tree, with control on the indentation. */ @Test public void testTreeFormat() { final DefaultTreeTable.Node root = new DefaultTreeTable.Node("Node #1"); final DefaultTreeTable.Node branch = new DefaultTreeTable.Node("Node #2"); root.getChildren().add(branch); root.getChildren().add(new DefaultTreeTable.Node("Node #3")); branch.getChildren().add(new DefaultTreeTable.Node("Node #4")); final TreeTableFormat tf = new TreeTableFormat(null, null); tf.setVerticalLinePosition(2); assertMultilinesEquals( "Node #1\n" + " ├─Node #2\n" + " │ └─Node #4\n" + " └─Node #3\n", tf.format(new DefaultTreeTable(root))); }
assertTrue("Initial children list:", root.getChildren().isEmpty()); table.setRoot(root); assertTrue("Initial children list:", node1.getChildren().isEmpty()); assertSame("Specified parent:", root, node1.getParent()); assertSame("Children list after add:", node1, getSingleton(root.getChildren())); assertTrue("Initial children list:", node2.getChildren().isEmpty()); assertSame("Specified parent:", node1, node2.getParent()); assertSame("Children list after add:", node2, getSingleton(node1.getChildren())); assertSame("Independent children list:", node1, getSingleton(root.getChildren()));
/** * Creates a new node with the given parent. The new node is added to the parent * {@linkplain #getChildren() list of children} at the given index. The new node * will be able to store values for the same columns than the parent node. * * @param parent the parent of the new node. * @param index the index where to add the new node in the parent list of children. */ public Node(final Node parent, final int index) { ArgumentChecks.ensureNonNull("parent", parent); this.parent = parent; columnIndices = parent.columnIndices; final TreeNodeList addTo = (TreeNodeList) parent.getChildren(); ArgumentChecks.ensureValidIndex(addTo.size() + 1, index); addTo.addChild(index, this); }
/** * Creates a new node with the given parent. The new node is added to the parent * {@linkplain #getChildren() list of children} at the given index. The new node * will be able to store values for the same columns than the parent node. * * @param parent the parent of the new node. * @param index the index where to add the new node in the parent list of children. */ public Node(final Node parent, final int index) { ArgumentChecks.ensureNonNull("parent", parent); this.parent = parent; columnIndices = parent.columnIndices; final TreeNodeList addTo = (TreeNodeList) parent.getChildren(); ArgumentChecks.ensureValidIndex(addTo.size() + 1, index); addTo.addChild(index, this); }
/** * Creates a new node with the given parent. The new node is added at the end of the parent * {@linkplain #getChildren() list of children}. The new node will be able to store values * for the same columns than the parent node. * * @param parent the parent of the new node. */ public Node(final Node parent) { ArgumentChecks.ensureNonNull("parent", parent); this.parent = parent; columnIndices = parent.columnIndices; final TreeNodeList addTo = (TreeNodeList) parent.getChildren(); addTo.addChild(addTo.size(), this); }
/** * Creates a new node with the given parent. The new node is added at the end of the parent * {@linkplain #getChildren() list of children}. The new node will be able to store values * for the same columns than the parent node. * * @param parent the parent of the new node. */ public Node(final Node parent) { ArgumentChecks.ensureNonNull("parent", parent); this.parent = parent; columnIndices = parent.columnIndices; final TreeNodeList addTo = (TreeNodeList) parent.getChildren(); addTo.addChild(addTo.size(), this); }