@Test public void depthFirst() throws Exception { assertEquals(Collections.<Integer>emptyList(), SortingNode.<Integer>emptyRoot().depthFirst().collect(toList())); SortingNode<Integer> tree = new SortingNode.Builder<Integer>() .childNode(100) .siblingNode(200) .childNode(210) .siblingNode(220) .parent() .siblingNode(300) .siblingNode(400) .childNode(410) .siblingNode(420) .siblingNode(430) .childNode(431) .build(); assertEquals(asList(100, 200, 210, 220, 300, 400, 410, 420, 430, 431), tree.depthFirst().collect(toList())); SortingNode<Integer> n400 = tree.getChildren().get(3); assertEquals(asList(400, 410, 420, 430, 431), n400.depthFirst().collect(toList())); }
public Stream<T> depthFirst() { Stream<T> childStream = children.stream().flatMap(SortingNode::depthFirst); if (value == null) { return childStream; } else { return Stream.concat(Stream.of(value), childStream); } }
SortingNode { public Stream<T> depthFirst() { Stream<T> childStream = children.stream().flatMap(SortingNode::depthFirst); if (value == null) { return childStream; } else { return Stream.concat(Stream.of(value), childStream); } } }
SortingNode { public Stream<T> depthFirst() { Stream<T> childStream = children.stream().flatMap(SortingNode::depthFirst); if (value == null) { return childStream; } else { return Stream.concat(Stream.of(value), childStream); } } private  SortingNode(@Nullable T value,
      @Nullable SortingNode<T> parent,
      Stream<UnaryOperator<SortingNode<T>>> childrenFactory); private  SortingNode(@Nullable T value,
      @Nullable SortingNode<T> parent,
      ImmutableList<SortingNode<T>> children); }
SortingNode { public Stream<T> depthFirst() { Stream<T> childStream = children.stream().flatMap(SortingNode::depthFirst); if (value == null) { return childStream; } else { return Stream.concat(Stream.of(value), childStream); } } private  SortingNode(@Nullable T value,
      @Nullable SortingNode<T> parent,
      Stream<UnaryOperator<SortingNode<T>>> childrenFactory); private  SortingNode(@Nullable T value,
      @Nullable SortingNode<T> parent,
      ImmutableList<SortingNode<T>> children); @SuppressWarnings("unchecked") static SortingNode<T> emptyRoot(); @Override String toString(); @Nullable T getValue(); @Nullable SortingNode<T> getParent(); boolean hasParent(); boolean isRoot(); List<SortingNode<T>> getChildren(); boolean hasChild(); SortingNode<T> deepSort(Comparator<SortingNode<T>> comparator); String prettyPrint(); Stream<T> depthFirst(); Stream<T> breathFirst(); }
SortingNode { public Stream<T> depthFirst() { Stream<T> childStream = children.stream().flatMap(SortingNode::depthFirst); if (value == null) { return childStream; } else { return Stream.concat(Stream.of(value), childStream); } } private  SortingNode(@Nullable T value,
      @Nullable SortingNode<T> parent,
      Stream<UnaryOperator<SortingNode<T>>> childrenFactory); private  SortingNode(@Nullable T value,
      @Nullable SortingNode<T> parent,
      ImmutableList<SortingNode<T>> children); @SuppressWarnings("unchecked") static SortingNode<T> emptyRoot(); @Override String toString(); @Nullable T getValue(); @Nullable SortingNode<T> getParent(); boolean hasParent(); boolean isRoot(); List<SortingNode<T>> getChildren(); boolean hasChild(); SortingNode<T> deepSort(Comparator<SortingNode<T>> comparator); String prettyPrint(); Stream<T> depthFirst(); Stream<T> breathFirst();  }