@Test public void testGetLeafs() { DAG<Integer> dag = DAG.of(1, 2, 3); dag.add(4, 2, 3); dag.add(5, 4, 2); dag.add(6, 5, 3); Collection<Node<Integer>> leafs = dag.getLeafs(); assertEquals(2, leafs.size()); assertTrue(leafs.contains(new Node<>(1))); assertTrue(leafs.contains(new Node<>(6))); }
public Collection<Node<T>> getLeafs() { return nodeMap.values().stream().filter(n -> n.children.isEmpty()) .collect(Collectors.toList()); }
DAG { public Collection<Node<T>> getLeafs() { return nodeMap.values().stream().filter(n -> n.children.isEmpty()) .collect(Collectors.toList()); } }
DAG { public Collection<Node<T>> getLeafs() { return nodeMap.values().stream().filter(n -> n.children.isEmpty()) .collect(Collectors.toList()); } private  DAG(); }
DAG { public Collection<Node<T>> getLeafs() { return nodeMap.values().stream().filter(n -> n.children.isEmpty()) .collect(Collectors.toList()); } private  DAG(); static DAG<T> empty(); @SuppressWarnings("unchecked") static DAG<T> of(T ...rootElements); static DAG<T> of(Iterable<T> rootElements); @SafeVarargs final DAG<T> add(T elem, T... parents); DAG<T> add(T elem, List<T> parents); Node<T> getNode(T elem); Collection<Node<T>> getRoots(); Collection<Node<T>> getLeafs(); DAG<T> parentSubGraph(T elem); int size(); Stream<T> nodes(); Stream<Node<T>> traverse(); @Override String toString(); }
DAG { public Collection<Node<T>> getLeafs() { return nodeMap.values().stream().filter(n -> n.children.isEmpty()) .collect(Collectors.toList()); } private  DAG(); static DAG<T> empty(); @SuppressWarnings("unchecked") static DAG<T> of(T ...rootElements); static DAG<T> of(Iterable<T> rootElements); @SafeVarargs final DAG<T> add(T elem, T... parents); DAG<T> add(T elem, List<T> parents); Node<T> getNode(T elem); Collection<Node<T>> getRoots(); Collection<Node<T>> getLeafs(); DAG<T> parentSubGraph(T elem); int size(); Stream<T> nodes(); Stream<Node<T>> traverse(); @Override String toString();  }