void (final Collection<? extends TreeItem<Pair<AbstractUrl, String>>> coll, Consumer<? super TreeItem<Pair<AbstractUrl, String>>> consumer) { final ArrayDeque<TreeItem<Pair<AbstractUrl, String>>> queue = new ArrayDeque<>(coll); while (!queue.isEmpty()) { final TreeItem<Pair<AbstractUrl, String>> item = queue.removeFirst(); consumer.consume(item); final List<TreeItem<Pair<AbstractUrl, String>>> children = item.getChildren(); if (children != null && !children.isEmpty()) { queue.addAll(children); } } }