TreeWalker { protected @Nullable CommandNode<R> map(CommandNode<T> command, @Nullable T source) { if (source != null && command.getRequirement() != null && !command.canUse(source)) { return null; } var result = mappings.get(command); if (result == null) { result = mapper.map(command); mappings.put(command, result); redirect(command.getRedirect(), result, source); descend(command.getChildren(), result, source); } return result; } 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 map() { var a = Literal.<String>builder("a").then(Literal.<String>builder("b").requires(val -> false).build()).build(); var c = Literal.<String>builder("c").redirect(a).build(); var d = Literal.<String>builder("d").then(c).build(); root.addChild(a); root.addChild(c); root.addChild(d); var mapped = tree.map(root, ""); var empty = mapped.getChild("a"); var same = mapped.getChild("d").getChild("c"); assertEquals("", mapped.getName()); assertEquals(0, empty.getChildren().size()); assertSame(empty, mapped.getChild("c").getRedirect()); assertSame(mapped.getChild("c"), same); }