本文整理汇总了Java中io.vavr.collection.Tree类的典型用法代码示例。如果您正苦于以下问题:Java Tree类的具体用法?Java Tree怎么用?Java Tree使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Tree类属于io.vavr.collection包,在下文中一共展示了Tree类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: prettyPrint
import io.vavr.collection.Tree; //导入依赖的package包/类
private static <T> void prettyPrint(Tree.Node<T> treeNode, String indent, String indent2, StringBuilder s) {
final String[] lines = treeNode.get().toString().split("\n");
s.append(lines[0]);
for (int i = 1; i < lines.length; i++) {
s.append('\n')
.append(indent2)
.append(lines[i]);
}
for (List<Tree.Node<T>> it = treeNode.getChildren(); it.nonEmpty(); it = it.tail()) {
final boolean isLast = it.tail().isEmpty();
s.append('\n')
.append(indent)
.append(isLast ? "└──" : "├──");
prettyPrint(it.head(), indent + (isLast ? " " : "│ "), indent + (isLast ? " " : "│ "), s);
}
}
示例2: pp
import io.vavr.collection.Tree; //导入依赖的package包/类
public static <T> String pp(Tree<T> tree) {
Objects.requireNonNull(tree, "tree is null");
if (tree.isEmpty()) { return "▣"; }
final StringBuilder builder = new StringBuilder();
prettyPrint((Tree.Node<T>) tree, "", "", builder);
return builder.toString();
}
示例3: box
import io.vavr.collection.Tree; //导入依赖的package包/类
public static <T> Box box(Tree<T> tree) {
Objects.requireNonNull(tree, "tree is null");
if (tree.isEmpty())
return Box.of("▣");
Tuple2<Box, Integer> x = nodeToBox((Node<T>) tree);
return Box.col(Box.row(Box.of('┌'), Box.of('─', x._2-2, 1), Box.of('┐')), x._1);
}
示例4: processTree
import io.vavr.collection.Tree; //导入依赖的package包/类
private int processTree(Tree<?> tree, String parentLabel, int index) {
Object value = tree.getValue();
String label = "lbl" + index;
labels.put(label, value.toString());
if(parentLabel != null) {
edges.add(parentLabel + " -> " + label);
}
for (Tree.Node<?> child : tree.getChildren()) {
index = processTree(child, label, index + 1);
}
return index;
}
示例5: 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" +
"");
}
示例6: next
import io.vavr.collection.Tree; //导入依赖的package包/类
@Override
public <T> T next(final InstanceType<T> instanceType, final FixtureContract fixture) {
return (T)new Tree.Node(
fixture.create(instanceType.getNestedGenericType1()),
List.empty()
);
}
示例7: nextEmpty
import io.vavr.collection.Tree; //导入依赖的package包/类
@Override
public <T> T nextEmpty(final InstanceType<T> instanceType, final FixtureContract fixture) {
return (T) new Tree.Node(
fixture.createDummy(instanceType.getNestedGenericType1()),
List.empty()
);
}
示例8: accepts
import io.vavr.collection.Tree; //导入依赖的package包/类
@Override
public boolean accepts(Class<?> type) {
return Tree.class.isAssignableFrom(type);
}
示例9: newContainerBuilderFor
import io.vavr.collection.Tree; //导入依赖的package包/类
@Override
public ContainerBuilder<Tree<?>> newContainerBuilderFor(Class<?> type) {
return new TreeContainerBuilder();
}
示例10: add
import io.vavr.collection.Tree; //导入依赖的package包/类
@Override
public ContainerBuilder<Tree<?>> add(Object it) {
list.add(it);
return this;
}
示例11: build
import io.vavr.collection.Tree; //导入依赖的package包/类
@Override
public Tree<?> build() {
return Tree.ofAll(list);
}
示例12: findStartDatesAsTree
import io.vavr.collection.Tree; //导入依赖的package包/类
@SqlQuery("SELECT start_date FROM tasks")
Tree<LocalDate> findStartDatesAsTree();
示例13: create
import io.vavr.collection.Tree; //导入依赖的package包/类
public static DotFile create(Tree<?> tree) {
return new DotFile(tree);
}
示例14: write
import io.vavr.collection.Tree; //导入依赖的package包/类
public static void write(Tree<?> tree, File file) throws IOException {
FileWriter writer = new FileWriter(file);
writer.write(create(tree).toString());
writer.close();
}
示例15: DotFile
import io.vavr.collection.Tree; //导入依赖的package包/类
private DotFile(Tree<?> tree) {
processTree(tree, null, 0);
}