当前位置: 首页>>代码示例>>Java>>正文


Java Tree.of方法代码示例

本文整理汇总了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" +
                            "");
}
 
开发者ID:vavr-io,项目名称:vavr-render,代码行数:36,代码来源:TreeTest.java

示例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");



}
 
开发者ID:vavr-io,项目名称:vavr-render,代码行数:54,代码来源:PrettyPrinterTest.java


注:本文中的io.vavr.collection.Tree.of方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。