diff --git a/maven.xml b/maven.xml new file mode 100644 index 0000000..793316a --- /dev/null +++ b/maven.xml @@ -0,0 +1,3 @@ + + + diff --git a/project.xml b/project.xml index fdc69e9..efa996a 100644 --- a/project.xml +++ b/project.xml @@ -2,9 +2,9 @@ 3 - commons-graph - Graph - 0.8 + commons-graph + Graph + 0.8.1 Apache Software Foundation @@ -23,7 +23,7 @@ http://jakarta.apache.org/commons/graph/ - scm:cvs:anoncvs@cvs.apache.org:/home/cvspublic:jakarta-commons/graph2 + scm:cvs:anoncvs@cvs.apache.org:/home/cvspublic:jakarta-commons-sandbox/graph2 http://cvs.apache.org/viewcvs/jakarta-commons-sandbox/graph2 @@ -110,7 +110,7 @@ - **/*Test.class + **/*Test.java diff --git a/src/java/org/apache/commons/graph/domain/dependency/DependencyGraph.java b/src/java/org/apache/commons/graph/domain/dependency/DependencyGraph.java index 2efe8b8..d8f2fd9 100644 --- a/src/java/org/apache/commons/graph/domain/dependency/DependencyGraph.java +++ b/src/java/org/apache/commons/graph/domain/dependency/DependencyGraph.java @@ -8,11 +8,14 @@ import org.apache.commons.graph.factory.GraphFactory; import org.apache.commons.graph.decorator.DDirectedGraph; import org.apache.commons.graph.dependency.exception.*; -import java.util.Map; -import java.util.List; -import java.util.HashMap; -import java.util.Iterator; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * Description of the Class @@ -49,7 +52,7 @@ public class DependencyGraph private void init() { } - + /** * Adds a feature to the Dependencies attribute of the DependencyGraph * object @@ -114,6 +117,98 @@ public class DependencyGraph { return visitor.getSortedDependencies(this, findVertex(head)); } + + /** Retrieve the vertices in a flattened, sorted, valid order. + * + * @return The list of vertices in a valid order. + */ + public List getSortedVertices() + { + Set vertices = new HashSet( getVertices() ); + List sortedDeps = new ArrayList( vertices.size() ); + + Vertex vertex = null; + List deps = null; + + DependencyVisitor visitor = new DependencyVisitor(); + + // While we still have unaccounted-for vertices + + while ( ! vertices.isEmpty() ) + { + // System.err.println( "--------------------------" ); + + // System.err.println( "## vertices = " + dumpVertices( vertices ) ); + // pick a vertex + vertex = (Vertex) vertices.iterator().next(); + + // System.err.println( "## vertex = " + ((Project)((DependencyVertex)vertex).getValue()).getId() ); + + // finds its sorted dependencies (including itself) + deps = visitor.getSortedDependencies( this, vertex ); + + // System.err.println( "## deps = " + dumpVertices( deps ) ); + + DependencyVertex eachVertex = null; + + // for each dependency... + for (Iterator i = deps.iterator(); i.hasNext();) + { + eachVertex = findVertex( i.next() ); + + // if we haven't accounted for the dependency + if ( vertices.contains( eachVertex ) ) + { + // account for it. + vertices.remove( eachVertex ); + + // tag it to the tail end of the sorted list. + sortedDeps.add( eachVertex.getValue() ); + } + } + } + + return sortedDeps; + } + + /* + protected String dumpVertices(Collection vertices) + { + StringBuffer buf = new StringBuffer(); + + buf.append( "{" ); + + Iterator vertIter = vertices.iterator(); + + Object eachVertex = null; + DependencyVertex vertex = null; + + while ( vertIter.hasNext() ) + { + eachVertex = (Object) vertIter.next(); + + if ( eachVertex instanceof DependencyVertex) + { + vertex = (DependencyVertex) eachVertex; + } + else + { + vertex = findVertex( eachVertex ); + } + + buf.append( ((Project)vertex.getValue()).getId() ); + + if ( vertIter.hasNext() ) + { + buf.append( ", " ); + } + } + + buf.append( "}" ); + + return buf.toString(); + } + */ }