You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2012/01/23 10:07:48 UTC

svn commit: r1234709 - in /commons/sandbox/graph/trunk/src: main/java/org/apache/commons/graph/ main/java/org/apache/commons/graph/scc/ test/java/org/apache/commons/graph/visit/

Author: simonetripodi
Date: Mon Jan 23 09:07:48 2012
New Revision: 1234709

URL: http://svn.apache.org/viewvc?rev=1234709&view=rev
Log:
shortcutted the visit algoritms call - each family of algorithms accepts a different kind of graph inputs (Dijkstra for example can be applied on directed graphes with weighted edges) that can be checked by the compiler, so the on(Graph) method is really too much generic

Modified:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/CheriyanMehlhornGabow.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/CheriyanMehlhornGabowVisitHandler.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/KosarajuSharir.java
    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/visit/VisitTestCase.java

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java?rev=1234709&r1=1234708&r2=1234709&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java Mon Jan 23 09:07:48 2012
@@ -46,10 +46,10 @@ public final class CommonsGraph<V extend
      * @param graph the Graph instance to apply graph algorithms
      * @return the graph algorithms selector
      */
-    public static <V extends Vertex, E extends Edge, G extends Graph<V, E>> CommonsGraph<V, E, G> on( G graph )
+    public static <V extends Vertex, E extends Edge, G extends Graph<V, E>> VisitSourceSelector<V, E, G> visit( G graph )
     {
         graph = checkNotNull( graph, "No algorithm can be applied on null graph!" );
-        return new CommonsGraph<V, E, G>( graph );
+        return new DefaultVisitSourceSelector<V, E, G>( graph );
     }
 
     /**
@@ -112,26 +112,11 @@ public final class CommonsGraph<V extend
     }
 
     /**
-     * The Graph instance to apply graph algorithms.
-     */
-    private final G graph;
-
-    /**
      * Hidden constructor, this class cannot be instantiated.
      */
-    private CommonsGraph( G graph )
+    private CommonsGraph()
     {
-        this.graph = graph;
-    }
-
-    /**
-     * Applies graph visit algorithms on input graph.
-     *
-     * @return the graph visit algorithms selector
-     */
-    public VisitSourceSelector<V, E, G> visit()
-    {
-        return new DefaultVisitSourceSelector<V, E, G>( graph );
+        // do nothing
     }
 
 }

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/CheriyanMehlhornGabow.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/CheriyanMehlhornGabow.java?rev=1234709&r1=1234708&r2=1234709&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/CheriyanMehlhornGabow.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/CheriyanMehlhornGabow.java Mon Jan 23 09:07:48 2012
@@ -19,7 +19,7 @@ package org.apache.commons.graph.scc;
  * under the License.
  */
 
-import static org.apache.commons.graph.CommonsGraph.on;
+import static org.apache.commons.graph.CommonsGraph.visit;
 
 import java.util.HashSet;
 import java.util.Set;
@@ -60,7 +60,7 @@ public final class CheriyanMehlhornGabow
         {
             if ( !marked.contains( vertex ) )
             {
-                on( graph ).visit().from( vertex ).applyingDepthFirstSearch( visitHandler );
+                visit( graph ).from( vertex ).applyingDepthFirstSearch( visitHandler );
             }
         }
     }

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/CheriyanMehlhornGabowVisitHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/CheriyanMehlhornGabowVisitHandler.java?rev=1234709&r1=1234708&r2=1234709&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/CheriyanMehlhornGabowVisitHandler.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/CheriyanMehlhornGabowVisitHandler.java Mon Jan 23 09:07:48 2012
@@ -19,7 +19,7 @@ package org.apache.commons.graph.scc;
  * under the License.
  */
 
-import static org.apache.commons.graph.CommonsGraph.on;
+import static org.apache.commons.graph.CommonsGraph.visit;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -84,7 +84,7 @@ final class CheriyanMehlhornGabowVisitHa
     {
         if ( !marked.contains( tail ) )
         {
-            on( graph ).visit().from( tail ).applyingDepthFirstSearch( this );
+            visit( graph ).from( tail ).applyingDepthFirstSearch( this );
         }
         else if ( !sscId.containsKey( tail ) )
         {

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/KosarajuSharir.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/KosarajuSharir.java?rev=1234709&r1=1234708&r2=1234709&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/KosarajuSharir.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/KosarajuSharir.java Mon Jan 23 09:07:48 2012
@@ -19,7 +19,7 @@ package org.apache.commons.graph.scc;
  * under the License.
  */
 
-import static org.apache.commons.graph.CommonsGraph.on;
+import static org.apache.commons.graph.CommonsGraph.visit;
 
 import org.apache.commons.graph.DirectedGraph;
 import org.apache.commons.graph.Edge;
@@ -50,7 +50,7 @@ public final class KosarajuSharir
     public static <V extends Vertex, E extends Edge> void hasStronglyConnectedComponent( DirectedGraph<V, E> graph ,
                                                                                          V source)
     {
-        on( graph ).visit().from( source ).applyingDepthFirstSearch( new KosarajuSharirVisitHandler<V, E>( source ) );
+        visit( graph ).from( source ).applyingDepthFirstSearch( new KosarajuSharirVisitHandler<V, E>( source ) );
 
         DirectedGraph<V, E> reverted = new RevertedGraph<V, E>( graph );
     }

Modified: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/visit/VisitTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/visit/VisitTestCase.java?rev=1234709&r1=1234708&r2=1234709&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/visit/VisitTestCase.java (original)
+++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/visit/VisitTestCase.java Mon Jan 23 09:07:48 2012
@@ -20,7 +20,7 @@ package org.apache.commons.graph.visit;
  */
 
 import static org.apache.commons.graph.CommonsGraph.newUndirectedMutableGraph;
-import static org.apache.commons.graph.CommonsGraph.on;
+import static org.apache.commons.graph.CommonsGraph.visit;
 import static org.junit.Assert.assertEquals;
 
 import java.util.ArrayList;
@@ -113,7 +113,7 @@ public final class VisitTestCase
 
         // actual graph
 
-        Graph<BaseLabeledVertex, BaseLabeledEdge> actual = on( input ).visit().from( new BaseLabeledVertex( "s" ) ).applyingBreadthFirstSearch();
+        Graph<BaseLabeledVertex, BaseLabeledEdge> actual = visit( input ).from( new BaseLabeledVertex( "s" ) ).applyingBreadthFirstSearch();
 
         // assertion
 
@@ -180,7 +180,7 @@ public final class VisitTestCase
         NodeSequenceVisitor<BaseLabeledVertex, BaseLabeledEdge> visitor =
             new NodeSequenceVisitor<BaseLabeledVertex, BaseLabeledEdge>();
 
-        on( input ).visit().from( new BaseLabeledVertex( "S" ) ).applyingDepthFirstSearch( visitor );
+        visit( input ).from( new BaseLabeledVertex( "S" ) ).applyingDepthFirstSearch( visitor );
 
         final List<BaseLabeledVertex> actual = visitor.getVertices();