[jboss-svn-commits] JBoss Common SVN: r2228 - in common-core/trunk: . src/main/java/org/jboss/util/graph
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Jan 2 23:36:47 EST 2007
Author: scott.stark at jboss.org
Date: 2007-01-02 23:36:45 -0500 (Tue, 02 Jan 2007)
New Revision: 2228
Modified:
common-core/trunk/pom.xml
common-core/trunk/src/main/java/org/jboss/util/graph/Graph.java
Log:
Add a root vertex notion to the Graph and set version to 2.0.4.Alpha2
Modified: common-core/trunk/pom.xml
===================================================================
--- common-core/trunk/pom.xml 2007-01-02 19:15:31 UTC (rev 2227)
+++ common-core/trunk/pom.xml 2007-01-03 04:36:45 UTC (rev 2228)
@@ -4,7 +4,7 @@
<groupId>jboss</groupId>
<artifactId>jboss-common-core</artifactId>
<packaging>jar</packaging>
- <version>2.0.4.Beta</version>
+ <version>2.0.4.Alpha2</version>
<name>JBoss Common Classes</name>
<url>http://www.jboss.org</url>
<description>A set of commonly used classed classes</description>
@@ -70,7 +70,8 @@
<archive>
<manifest>
<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
- <addDefaultImplementationEntries>true</addDefaultImplementationEntries> </manifest>
+ <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+ </manifest>
</archive>
</configuration>
</plugin>
Modified: common-core/trunk/src/main/java/org/jboss/util/graph/Graph.java
===================================================================
--- common-core/trunk/src/main/java/org/jboss/util/graph/Graph.java 2007-01-02 19:15:31 UTC (rev 2227)
+++ common-core/trunk/src/main/java/org/jboss/util/graph/Graph.java 2007-01-03 04:36:45 UTC (rev 2228)
@@ -45,6 +45,8 @@
private ArrayList<Vertex<T>> verticies;
/** Vector<Edge> of edges in the graph */
private ArrayList<Edge<T>> edges;
+ /** The vertex identified as the root of the graph */
+ private Vertex<T> rootVertex;
/**
* Construct a new graph without any vertices or edges
@@ -89,6 +91,26 @@
}
/**
+ * Get the root vertex
+ * @return the root vertex if one is set, null if no vertex has been set as the root.
+ */
+ public Vertex<T> getRootVertex()
+ {
+ return rootVertex;
+ }
+ /**
+ * Set a root vertex. If root does no exist in the graph it is added.
+ * @param root - the vertex to set as the root and optionally add if it
+ * does not exist in the graph.
+ */
+ public void setRootVertex(Vertex<T> root)
+ {
+ this.rootVertex = root;
+ if( verticies.contains(root) == false )
+ this.addVertex(root);
+ }
+
+ /**
* Get the given Vertex.
* @param n the index [0, size()-1] of the Vertex to access
* @return the nth Vertex
@@ -165,27 +187,31 @@
/**
* Remove a vertex from the graph
- * @param from the Vertex to remove
+ * @param v the Vertex to remove
* @return true if the Vertex was removed
*/
- public boolean removeVertex(Vertex<T> from)
+ public boolean removeVertex(Vertex<T> v)
{
- if (!verticies.contains(from))
+ if (!verticies.contains(v))
return false;
- verticies.remove(from);
- for(int n = 0; n < from.getOutgoingEdgeCount(); n ++)
+ verticies.remove(v);
+ if( v == rootVertex )
+ rootVertex = null;
+
+ // Remove the edges associated with v
+ for(int n = 0; n < v.getOutgoingEdgeCount(); n ++)
{
- Edge<T> e = from.getOutgoingEdge(n);
- from.remove(e);
+ Edge<T> e = v.getOutgoingEdge(n);
+ v.remove(e);
Vertex<T> to = e.getTo();
to.remove(e);
edges.remove(e);
}
- for(int n = 0; n < from.getIncomingEdgeCount(); n ++)
+ for(int n = 0; n < v.getIncomingEdgeCount(); n ++)
{
- Edge<T> e = from.getIncomingEdge(n);
- from.remove(e);
+ Edge<T> e = v.getIncomingEdge(n);
+ v.remove(e);
Vertex<T> predecessor = e.getFrom();
predecessor.remove(e);
}
More information about the jboss-svn-commits
mailing list