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/22 21:14:49 UTC

svn commit: r1234591 - in /commons/sandbox/graph/trunk/src: main/java/org/apache/commons/graph/ main/java/org/apache/commons/graph/builder/ test/java/org/apache/commons/graph/builder/

Author: simonetripodi
Date: Sun Jan 22 20:14:48 2012
New Revision: 1234591

URL: http://svn.apache.org/viewvc?rev=1234591&view=rev
Log:
[SANDBOX-366] moved MutableGraph builder APIs in the central CommonsGraph class

Removed:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/GraphBuilder.java
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/builder/DefaultLinkedConnectionBuilder.java
    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.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=1234591&r1=1234590&r2=1234591&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 Sun Jan 22 20:14:48 2012
@@ -21,6 +21,13 @@ package org.apache.commons.graph;
 
 import static org.apache.commons.graph.utils.Assertions.checkNotNull;
 
+import org.apache.commons.graph.builder.DefaultLinkedConnectionBuilder;
+import org.apache.commons.graph.builder.GraphConnection;
+import org.apache.commons.graph.builder.LinkedConnectionBuilder;
+import org.apache.commons.graph.model.DirectedMutableGraph;
+import org.apache.commons.graph.model.DirectedMutableWeightedGraph;
+import org.apache.commons.graph.model.UndirectedMutableGraph;
+import org.apache.commons.graph.model.UndirectedMutableWeightedGraph;
 import org.apache.commons.graph.visit.DefaultVisitSourceSelector;
 import org.apache.commons.graph.visit.VisitSourceSelector;
 
@@ -46,6 +53,65 @@ public final class CommonsGraph<V extend
     }
 
     /**
+     * Creates a new {@link DirectedMutableGraph} instance where vertices
+     * are connected as described in the input {@link GraphConnection} instance.
+     *
+     * @param graphConnection the {@link GraphConnection} instance that describes vertices
+     * @return a new {@link DirectedMutableGraph} instance
+     */
+    public static <V extends Vertex, E extends Edge> DirectedMutableGraph<V, E> newDirectedMutableGraph( GraphConnection<V, E> graphConnection )
+    {
+        return populate( new DirectedMutableGraph<V, E>() ).withConnections( graphConnection );
+    }
+
+    /**
+     * Creates a new {@link DirectedMutableWeightedGraph} instance where vertices
+     * are connected as described in the input {@link GraphConnection} instance.
+     *
+     * @param graphConnection the {@link GraphConnection} instance that describes vertices
+     * @return a new {@link DirectedMutableWeightedGraph} instance
+     */
+    public static <V extends Vertex, WE extends WeightedEdge<W>, W> DirectedMutableWeightedGraph<V, WE, W> newDirectedMutableWeightedGraph( GraphConnection<V, WE> graphConnection )
+    {
+        return populate( new DirectedMutableWeightedGraph<V, WE, W>() ).withConnections( graphConnection );
+    }
+
+    /**
+     * Creates a new {@link UndirectedMutableGraph} instance where vertices
+     * are connected as described in the input {@link GraphConnection} instance.
+     *
+     * @param graphConnection the {@link GraphConnection} instance that describes vertices
+     * @return a new {@link UndirectedMutableGraph} instance
+     */
+    public static <V extends Vertex, E extends Edge> UndirectedMutableGraph<V, E> newUndirectedMutableGraph( GraphConnection<V, E> graphConnection )
+    {
+        return populate( new UndirectedMutableGraph<V, E>() ).withConnections( graphConnection );
+    }
+
+    /**
+     * Creates a new {@link UndirectedMutableWeightedGraph} instance where vertices
+     * are connected as described in the input {@link GraphConnection} instance.
+     *
+     * @param graphConnection the {@link GraphConnection} instance that describes vertices
+     * @return a new {@link UndirectedMutableWeightedGraph} instance
+     */
+    public static <V extends Vertex, WE extends WeightedEdge<W>, W> UndirectedMutableWeightedGraph<V, WE, W> newUndirectedMutableWeightedGraph( GraphConnection<V, WE> graphConnection )
+    {
+        return populate( new UndirectedMutableWeightedGraph<V, WE, W>() ).withConnections( graphConnection );
+    }
+
+    /**
+     * Allows populate the given {@link MutableGraph}.
+     *
+     * @param graph the graph has to be populated
+     * @return the builder to configure vertices connection
+     */
+    public static <V extends Vertex, E extends Edge, G extends MutableGraph<V, E>> LinkedConnectionBuilder<V, E, G> populate( G graph )
+    {
+        return new DefaultLinkedConnectionBuilder<V, E, G>( checkNotNull( graph, "Impossible to configure null graph!" ) );
+    }
+
+    /**
      * The Graph instance to apply graph algorithms.
      */
     private final G graph;

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultLinkedConnectionBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultLinkedConnectionBuilder.java?rev=1234591&r1=1234590&r2=1234591&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultLinkedConnectionBuilder.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/builder/DefaultLinkedConnectionBuilder.java Sun Jan 22 20:14:48 2012
@@ -25,7 +25,7 @@ import org.apache.commons.graph.Edge;
 import org.apache.commons.graph.MutableGraph;
 import org.apache.commons.graph.Vertex;
 
-final class DefaultLinkedConnectionBuilder<V extends Vertex, E extends Edge, G extends MutableGraph<V, E>>
+public final class DefaultLinkedConnectionBuilder<V extends Vertex, E extends Edge, G extends MutableGraph<V, E>>
     implements LinkedConnectionBuilder<V, E, G>
 {
 

Modified: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.java?rev=1234591&r1=1234590&r2=1234591&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.java (original)
+++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/builder/GraphBuilderTestCase.java Sun Jan 22 20:14:48 2012
@@ -19,7 +19,7 @@ package org.apache.commons.graph.builder
  * under the License.
  */
 
-import static org.apache.commons.graph.builder.GraphBuilder.newUndirectedMutableWeightedGraph;
+import static org.apache.commons.graph.CommonsGraph.newUndirectedMutableWeightedGraph;
 
 import static org.junit.Assert.assertEquals;