TreeWalker { public void prune(RootCommandNode<R> root, Collection<? extends CommandNode<T>> commands) { for (var child : commands) { Commands.remove(root, child.getName()); var result = map(child, null); if (result != null) { root.addChild(result); } } mappings.clear(); } TreeWalker(Mapper<T, R> mapper); void prune(RootCommandNode<R> root, Collection<? extends CommandNode<T>> commands); void add(RootCommandNode<R> root, Collection<? extends CommandNode<T>> commands, T source, Predicate<CommandNode<T>> requirement);  }
@Test void prune() { root.addChild(Literal.<String>builder("a").then(Literal.<String>builder("child").build()).build()); tree.prune(root, commands); assertEquals(3, root.getChildren().size()); assertNull(root.getChild("a").getChild("child")); }