class LdapGroupUtils {

    public Set<LdapGroup> findDescendantsForLdapGroupNode(LdapGroupNode startNode)
    {
        Set<LdapGroup> visitedNodes = new HashSet<>();

        Queue<LdapGroupNode> queue = new LinkedList<>();

        queue.add(startNode);

        while (!queue.isEmpty())
        {
            startNode = queue.poll();
            visitedNodes.add(startNode.getLdapGroup());

            startNode.getNodes().stream()
                    .filter(it -> !visitedNodes.contains(it.getLdapGroup()))
                    .forEach(queue::add);

        }
        return visitedNodes;
    }

}