private static <L> List<Tree<L>> spliceNodesHelper(Tree<L> tree, Filter<L> filter) {
    List<Tree<L>> splicedChildren = new ArrayList<Tree<L>>();
    for (Tree<L> child : tree.getChildren()) {
      List<Tree<L>> splicedChildList = spliceNodesHelper(child, filter);
      splicedChildren.addAll(splicedChildList);
    }
    if (filter.accept(tree.getLabel()))
      return splicedChildren;
    return Collections.singletonList(new Tree<L>(tree.getLabel(), splicedChildren));
  }