private static void gatherDescendents ( Vertex v, Map projectMap, Set out, Set visited ) { if ( visited.contains( v ) ) return; visited.add( v ); out.add( projectMap.get( v.getLabel() ) ); for ( Iterator i = v.getChildren().iterator(); i.hasNext(); ) { Vertex child = (Vertex) i.next(); gatherDescendents( child, projectMap, out, visited ); } }
private static void gatherAncestors ( Vertex v, Map projectMap, Set out, Set visited ) { if ( visited.contains( v ) ) return; visited.add( v ); out.add( projectMap.get( v.getLabel() ) ); for ( Iterator i = v.getParents().iterator(); i.hasNext(); ) { Vertex parent = (Vertex) i.next(); gatherAncestors( parent, projectMap, out, visited ); } }
/** * Adds vertex to DAG. If vertex of given label already exist in DAG no vertex is added * * @param label The label of the Vertex * @return New vertex if vertex of given label was not present in the DAG or existing vertex if vertex of given * label was already added to DAG */ public Vertex addVertex( final String label ) { Vertex retValue = null; // check if vertex is already in DAG if ( vertexMap.containsKey( label ) ) { retValue = vertexMap.get( label ); } else { retValue = new Vertex( label ); vertexMap.put( label, retValue ); vertexList.add( retValue ); } return retValue; }
log.debug("Vertices:"); for (Vertex v : graph.getVerticies()) { log.debug(" " + v.getLabel()); if (!v.getParents().isEmpty()) { log.debug(" parents:"); for (Vertex parent : v.getParents()) { log.debug(" " + parent.getLabel()); if (!v.getChildren().isEmpty()) { log.debug(" children:"); for (Vertex child : v.getChildren()) { log.debug(" " + child.getLabel());
/** * Get the labels used by the most direct children. * * @return the labels used by the most direct children. */ public List<String> getChildLabels() { final List<String> retValue = new ArrayList<String>( children.size() ); for ( Vertex vertex : children ) { retValue.add( vertex.getLabel() ); } return retValue; }
public boolean hasEdge( final String label1, final String label2 ) { final Vertex v1 = getVertex( label1 ); final Vertex v2 = getVertex( label2 ); final boolean retValue = v1.getChildren().contains( v2 ); return retValue; }
public void addEdge( final Vertex from, final Vertex to ) throws CycleDetectedException { from.addEdgeTo( to ); to.addEdgeFrom( from ); final List<String> cycle = CycleDetector.introducesCycle( to ); if ( cycle != null ) { // remove edge which introduced cycle removeEdge( from, to ); final String msg = "Edge between '" + from + "' and '" + to + "' introduces to cycle in the graph"; throw new CycleDetectedException( msg, cycle ); } }
/** * @param label * @return */ public List<String> getChildLabels( final String label ) { final Vertex vertex = getVertex( label ); return vertex.getChildLabels(); }
/** * Get the labels used by the most direct ancestors (parents). * * @return the labels used parents */ public List<String> getParentLabels() { final List<String> retValue = new ArrayList<String>( parents.size() ); for ( Vertex vertex : parents ) { retValue.add( vertex.getLabel() ); } return retValue; }
private static void dfsVisit( final Vertex vertex, final Map<Vertex, Integer> vertexStateMap, final List<String> list ) { vertexStateMap.put( vertex, VISITING ); for ( Vertex v : vertex.getChildren() ) { if ( isNotVisited( v, vertexStateMap ) ) { dfsVisit( v, vertexStateMap, list ); } } vertexStateMap.put( vertex, VISITED ); list.add( vertex.getLabel() ); }
String projectId = projectVertex.getLabel();
private static boolean dfsVisit( final Vertex vertex, final LinkedList<String> cycle, final Map<Vertex, Integer> vertexStateMap ) { cycle.addFirst( vertex.getLabel() ); vertexStateMap.put( vertex, VISITING ); for ( Vertex v : vertex.getChildren() ) { if ( isNotVisited( v, vertexStateMap ) ) { final boolean hasCycle = dfsVisit( v, cycle, vertexStateMap ); if ( hasCycle ) { return true; } } else if ( isVisiting( v, vertexStateMap ) ) { cycle.addFirst( v.getLabel() ); return true; } } vertexStateMap.put( vertex, VISITED ); cycle.removeFirst(); return false; }
private void addEdge( Vertex fromVertex, Vertex toVertex, MavenProject fromProject, Map<String, MavenProject> projectMap, boolean force, boolean safe ) throws CycleDetectedException { if ( fromVertex.equals( toVertex ) ) { return; } if ( fromProject != null ) { MavenProject toProject = projectMap.get( toVertex.getLabel() ); fromProject.addProjectReference( toProject ); } if ( force && toVertex.getChildren().contains( fromVertex ) ) { dag.removeEdge( toVertex, fromVertex ); } try { dag.addEdge( fromVertex, toVertex ); } catch ( CycleDetectedException e ) { if ( !safe ) { throw e; } } }