void (DFSTWalker walker) { ArrayDeque<Pair<NodeDescriptor, NodeDescriptor>> stack = StreamEx.of(myRootChildren).map(e -> new Pair<NodeDescriptor, NodeDescriptor>(null, e)).toCollection(ArrayDeque::new); while (!stack.isEmpty()) { Pair<NodeDescriptor, NodeDescriptor> nodeInfo = stack.pop(); NodeDescriptor child = nodeInfo.second; walker.visit(nodeInfo.first, child); List<NodeDescriptor> list = myChildrenMap.get(child); if (list != null) { iterateBackward(ContainerUtil.map(list, e -> new Pair<>(child, e))).forEach(stack::push); } } }