commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1136157 - /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java
Date Wed, 15 Jun 2011 19:31:49 GMT
Author: simonetripodi
Date: Wed Jun 15 19:31:49 2011
New Revision: 1136157

URL: http://svn.apache.org/viewvc?rev=1136157&view=rev
Log:
added internal utility method to check if Vertices in the given Edge are present in the Graph

Modified:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java?rev=1136157&r1=1136156&r2=1136157&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java
Wed Jun 15 19:31:49 2011
@@ -19,6 +19,7 @@ package org.apache.commons.graph.model;
  * under the License.
  */
 
+import static java.lang.String.format;
 import static java.util.Collections.unmodifiableSet;
 
 import java.util.HashMap;
@@ -28,6 +29,7 @@ import java.util.Set;
 
 import org.apache.commons.graph.Edge;
 import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.GraphException;
 import org.apache.commons.graph.Vertex;
 
 /**
@@ -104,4 +106,21 @@ public abstract class BaseGraph<V extend
         return allEdges;
     }
 
+    /**
+     * Utility method to check if Vertices in the given Edge are present in the Graph.
+     *
+     * @param e the Edge which Vertices have to be checked
+     */
+    protected final void checkEdge( E e )
+    {
+        if ( !adjacencyList.containsKey( e.getHead() ) )
+        {
+            throw new GraphException( format( "Vertex '%s' not present in the Graph", e.getHead()
) );
+        }
+        if ( !adjacencyList.containsKey( e.getTail() ) )
+        {
+            throw new GraphException( format( "Vertex '%s' not present in the Graph", e.getTail()
) );
+        }
+    }
+
 }



Mime
View raw message