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/31 13:23:08 UTC

svn commit: r1238435 - in /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectivity: DefaultConnectivityAlgorithmsSelector.java DefaultConnectivityBuilder.java

Author: simonetripodi
Date: Tue Jan 31 12:23:07 2012
New Revision: 1238435

URL: http://svn.apache.org/viewvc?rev=1238435&view=rev
Log:
moved the node selection logic from the algorithm execution to node selector itself

Modified:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectivity/DefaultConnectivityAlgorithmsSelector.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectivity/DefaultConnectivityBuilder.java

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectivity/DefaultConnectivityAlgorithmsSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectivity/DefaultConnectivityAlgorithmsSelector.java?rev=1238435&r1=1238434&r2=1238435&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectivity/DefaultConnectivityAlgorithmsSelector.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectivity/DefaultConnectivityAlgorithmsSelector.java Tue Jan 31 12:23:07 2012
@@ -19,7 +19,6 @@ package org.apache.commons.graph.connect
  * under the License.
  */
 
-import static java.util.Arrays.asList;
 import static org.apache.commons.graph.CommonsGraph.visit;
 
 import java.util.ArrayList;
@@ -40,12 +39,12 @@ final class DefaultConnectivityAlgorithm
 
     final private G graph;
 
-    final private V[] includedVertices;
+    final private Iterable<V> includedVertices;
 
-    public DefaultConnectivityAlgorithmsSelector( G graph, V... vertices )
+    public DefaultConnectivityAlgorithmsSelector( G graph, Iterable<V> includedVertices )
     {
         this.graph = graph;
-        this.includedVertices = vertices;
+        this.includedVertices = includedVertices;
     }
 
     /**
@@ -55,16 +54,9 @@ final class DefaultConnectivityAlgorithm
     {
         final List<V> untouchedVertices = new ArrayList<V>();
 
-        if ( includedVertices != null )
+        for ( V v : includedVertices )
         {
-            untouchedVertices.addAll( asList( includedVertices ) );
-        }
-        else
-        {
-            for ( V v : graph.getVertices() )
-            {
-                untouchedVertices.add( v );
-            }
+            untouchedVertices.add( v );
         }
 
         final Collection<List<V>> connectedVertices = new LinkedList<List<V>>();

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectivity/DefaultConnectivityBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectivity/DefaultConnectivityBuilder.java?rev=1238435&r1=1238434&r2=1238435&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectivity/DefaultConnectivityBuilder.java (original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectivity/DefaultConnectivityBuilder.java Tue Jan 31 12:23:07 2012
@@ -19,6 +19,10 @@ package org.apache.commons.graph.connect
  * under the License.
  */
 
+import static org.apache.commons.graph.utils.Assertions.checkNotNull;
+
+import static java.util.Arrays.asList;
+
 import org.apache.commons.graph.Edge;
 import org.apache.commons.graph.Graph;
 import org.apache.commons.graph.Vertex;
@@ -41,7 +45,9 @@ public class DefaultConnectivityBuilder<
      */
     public ConnectivityAlgorithmsSelector<V, E, G> includingVertices( V... vertices )
     {
-        return new DefaultConnectivityAlgorithmsSelector<V, E, G>( graph, vertices );
+        vertices = checkNotNull( vertices,
+                                 "Graph connectivity cannote be applied on null vertices array, use no-args if you intend specify no vertices" );
+        return new DefaultConnectivityAlgorithmsSelector<V, E, G>( graph, asList( vertices ) );
     }
 
     /**
@@ -49,7 +55,7 @@ public class DefaultConnectivityBuilder<
      */
     public ConnectivityAlgorithmsSelector<V, E, G> includingAllVertices()
     {
-        return new DefaultConnectivityAlgorithmsSelector<V, E, G>( graph, (V[]) null );
+        return new DefaultConnectivityAlgorithmsSelector<V, E, G>( graph, graph.getVertices() );
     }
 
 }