/** * Finds all the vertices at the opposite end of the edges from {@code referenceVertex}, filtered to include only those identified in {@code selection} * * @param referenceVertex the vertex at the centre of the 'query' * @param wantDependencies if true, select dependency edges, otherwise select dependant edges * @param selection the Dependency.Type(s) to include * @return list of vertices at the opposite end of the edges from {@code referenceVertex}, or an empty list if there are no edges */ private List<T> findRelations(T referenceVertex, boolean wantDependencies, Selection selection) { Collection<ServiceEdge> edges = wantDependencies ? getDependenciesEdges(referenceVertex) : getDependantsEdges(referenceVertex); EnumSet<Dependency.Type> selectionSet = selectionCriteria.get(selection); return edges.stream() .filter(edge -> selectionSet.contains(edge.getType())) .map(edge -> graph.getOpposite(referenceVertex, edge)) .collect(Collectors.toList()); }
public static <V,E> void addFromSubTree(Forest<V,E> tree, Forest<V,E> subTree, E edge, V parent, V root) { // add edge connecting parent and root to tree if(edge != null && parent != null) { tree.addEdge(edge, parent, root); } else { tree.addVertex(root); } Collection<E> outEdges = subTree.getOutEdges(root); for(E e : outEdges) { V opposite = subTree.getOpposite(root, e); addFromSubTree(tree, subTree, e, root, opposite); } } }
V opposite = subTree.getOpposite(root, e); addFromSubTree(tree, subTree, e, root, opposite);