you might be able to clean this up more if you made nodes of type List<? extends Collection> because then you shouldn't need to special-case empty and the separator.