@Test public void findDescendantsOfATest() { ldapGroupNode = new LdapGroupNode(a); ldapLdapGroupUtils = new LdapGroupUtils(); Set<LdapGroup> visited = ldapLdapGroupUtils.findDescendantsForLdapGroupNode(ldapGroupNode); assertThat("Visited should be", visited, everyItem(isIn(groups(a, b, c, b1, b2, c1, c2)))); }
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; }
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; } }
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; }  }
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; }  Set<LdapGroup> findDescendantsForLdapGroupNode(LdapGroupNode startNode); Set<LdapGroup> findAscendantsForLdapGroupNode(LdapGroupNode targetNode, Set<LdapGroup> ldapGroups); }
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; }  Set<LdapGroup> findDescendantsForLdapGroupNode(LdapGroupNode startNode); Set<LdapGroup> findAscendantsForLdapGroupNode(LdapGroupNode targetNode, Set<LdapGroup> ldapGroups);  }