예제 #1
0
  /**
   * @param tree
   * @return
   */
  @Pure
  @ExtensionMethod
  @ReturnNonnull
  @Recursive
  public static <T> AbstractUnmodifiableIterable<T> NodeValuesPostOrder(final IMultiTree<T> tree) {
    com.google.common.base.Preconditions.checkNotNull(tree);

    if (tree.IsTreeNode()) {
      final IMultiTreeNode<T> treeNode = tree.AsTreeNode();
      assert treeNode != null;

      return Iterables.Concat(
          Iterables.Concat(
              Iterables.Map(
                  treeNode.GetSubtrees(),
                  new Func1<IMultiTree<T>, Iterable<T>>() {

                    @Override
                    public Iterable<T> DoFunc(final IMultiTree<T> input) {
                      assert input != null;

                      return MultiTrees.NodeValuesPreOrder(input);
                    }
                  })),
          treeNode.GetNodeValue());

    } else {
      assert tree.IsEmptyTree();

      return Iterables.EmptyUnmodifiableIterable();
    }
  }
예제 #2
0
 /**
  * @param tree
  * @return
  */
 @SuppressWarnings("unchecked")
 @Pure
 @CheckForNull
 @ExtensionMethod
 public static <T> IMultiTreeNode<T> AsMultiTreeNodeWhenReadOnly(
     @Nullable final IMultiTree<? extends T> tree) {
   return MultiTrees.SafeCastWhenReadOnly(tree.AsTreeNode());
 }