本文整理汇总了Java中io.vavr.collection.Tree.of方法的典型用法代码示例。如果您正苦于以下问题:Java Tree.of方法的具体用法?Java Tree.of怎么用?Java Tree.of使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.vavr.collection.Tree
的用法示例。
在下文中一共展示了Tree.of方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import io.vavr.collection.Tree; //导入方法依赖的package包/类
@Test
public void test() {
final Tree<String> tree =
Tree.of("Ann",
Tree.of("Mary",
Tree.of("John",
Tree.of("Avila")),
Tree.of("Karen"),
Tree.of("Steven\nAbbot\nBraddock")),
Tree.of("Peter",
Tree.of("Paul\nPalucci"),
Tree.of("Anthony")));
final DefaultMutableTreeNode t = io.vavr.render.swing.Tree.create(tree);
@SuppressWarnings("rawtypes")
final Enumeration v = t.preorderEnumeration();
final StringBuilder builder = new StringBuilder();
while (v.hasMoreElements())
builder.append(v.nextElement()).append('\n');
final String s = builder.toString();
assertThat(s).isEqualTo("Ann\n" +
"Mary\n" +
"John\n" +
"Avila\n" +
"Karen\n" +
"Steven\n" +
"Abbot\n" +
"Braddock\n" +
"Peter\n" +
"Paul\n" +
"Palucci\n" +
"Anthony\n" +
"");
}
示例2: shouldPrettyPrintTree
import io.vavr.collection.Tree; //导入方法依赖的package包/类
@Test
public void shouldPrettyPrintTree() {
final Tree<String> empty = Tree.empty();
assertThat(PrettyPrinter.pp(empty)).isEqualTo("▣");
final Tree<String> tree1 = Tree.of("TEST");
assertThat(PrettyPrinter.pp(tree1)).isEqualTo("TEST");
final Tree<String> ast =
Tree.of("IfExp",
Tree.of("BoolExp: false"),
Tree.of("IntExp: 10"),
Tree.of("IntExp: 20"));
assertThat(PrettyPrinter.pp(ast)).isEqualTo("IfExp\n" +
"├──BoolExp: false\n" +
"├──IntExp: 10\n" +
"└──IntExp: 20");
final Tree<String> persons =
Tree.of("Ann",
Tree.of("Mary",
Tree.of("John",
Tree.of("Avila")),
Tree.of("Karen",
Tree.of("Frank")),
Tree.of("Steven\nAbbot\nBraddock")),
Tree.of("Peter",
Tree.of("Paul\nPalucci"),
Tree.of("Anthony")),
Tree.of("Christopher",
Tree.of("Samuel")));
assertThat(PrettyPrinter.pp(persons)).isEqualTo("Ann\n" +
"├──Mary\n" +
"│ ├──John\n" +
"│ │ └──Avila\n" +
"│ ├──Karen\n" +
"│ │ └──Frank\n" +
"│ └──Steven\n" +
"│ Abbot\n" +
"│ Braddock\n" +
"├──Peter\n" +
"│ ├──Paul\n" +
"│ │ Palucci\n" +
"│ └──Anthony\n" +
"└──Christopher\n" +
" └──Samuel");
}