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:04:57 UTC
svn commit: r1234588 - in /commons/sandbox/graph/trunk/src: changes/
main/java/org/apache/commons/graph/ main/java/org/apache/commons/graph/scc/
main/java/org/apache/commons/graph/visit/
test/java/org/apache/commons/graph/visit/
Author: simonetripodi
Date: Sun Jan 22 20:04:57 2012
New Revision: 1234588
URL: http://svn.apache.org/viewvc?rev=1234588&view=rev
Log:
[SANDBOX-366] Move Graph algorithms APIs to fluent APIs (moved Visit algorithms only)
Added:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitSourceSelector.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitAlgorithmsSelector.java (with props)
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitSourceSelector.java (with props)
Removed:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/Visit.java
Modified:
commons/sandbox/graph/trunk/src/changes/changes.xml
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/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/changes/changes.xml?rev=1234588&r1=1234587&r2=1234588&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/changes/changes.xml (original)
+++ commons/sandbox/graph/trunk/src/changes/changes.xml Sun Jan 22 20:04:57 2012
@@ -23,6 +23,9 @@
</properties>
<body>
<release version="0.1" date="201?-??-??" description="First release.">
+ <action dev="simonetripodi" type="update" issue="SANDBOX-366">
+ Move Graph algorithms APIs to fluent APIs
+ </action>
<action dev="simonetripodi" type="update" issue="SANDBOX-364" due-to="Claudio Squarcella">
Adding generic weight type to model
</action>
Added: 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=1234588&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java Sun Jan 22 20:04:57 2012
@@ -0,0 +1,71 @@
+package org.apache.commons.graph;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.commons.graph.utils.Assertions.checkNotNull;
+
+import org.apache.commons.graph.visit.DefaultVisitSourceSelector;
+import org.apache.commons.graph.visit.VisitSourceSelector;
+
+/**
+ * The Apache Commons Graph package is a toolkit for managing graphs and graph based data structures.
+ */
+public final class CommonsGraph<V extends Vertex, E extends Edge, G extends Graph<V, E>>
+{
+
+ /**
+ * Allows select a series of algorithms to apply on input graph.
+ *
+ * @param <V> the Graph vertices type
+ * @param <E> the Graph edges type
+ * @param <G> the Graph type
+ * @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 )
+ {
+ graph = checkNotNull( graph, "No algorithm can be applied on null graph!" );
+ return new CommonsGraph<V, E, G>( graph );
+ }
+
+ /**
+ * The Graph instance to apply graph algorithms.
+ */
+ private final G graph;
+
+ /**
+ * Hidden constructor, this class cannot be instantiated.
+ */
+ private CommonsGraph( G graph )
+ {
+ 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 );
+ }
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/CommonsGraph.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=1234588&r1=1234587&r2=1234588&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 Sun Jan 22 20:04:57 2012
@@ -19,7 +19,7 @@ package org.apache.commons.graph.scc;
* under the License.
*/
-import static org.apache.commons.graph.visit.Visit.depthFirstSearch;
+import static org.apache.commons.graph.CommonsGraph.on;
import java.util.HashSet;
import java.util.Set;
@@ -60,7 +60,7 @@ public final class CheriyanMehlhornGabow
{
if ( !marked.contains( vertex ) )
{
- depthFirstSearch( graph, vertex, visitHandler );
+ on( graph ).visit().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=1234588&r1=1234587&r2=1234588&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 Sun Jan 22 20:04:57 2012
@@ -19,7 +19,7 @@ package org.apache.commons.graph.scc;
* under the License.
*/
-import static org.apache.commons.graph.visit.Visit.depthFirstSearch;
+import static org.apache.commons.graph.CommonsGraph.on;
import java.util.HashMap;
import java.util.Map;
@@ -84,7 +84,7 @@ final class CheriyanMehlhornGabowVisitHa
{
if ( !marked.contains( tail ) )
{
- depthFirstSearch( graph, tail, this );
+ on( graph ).visit().from( tail ).applyingDepthFirstSearch( this );
}
else if ( !sscId.containsKey( tail ) )
{
@@ -107,7 +107,7 @@ final class CheriyanMehlhornGabowVisitHa
while ( !head.equals( w ) );
sscCounter++;
}
-
+
return true;
}
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=1234588&r1=1234587&r2=1234588&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 Sun Jan 22 20:04:57 2012
@@ -19,7 +19,7 @@ package org.apache.commons.graph.scc;
* under the License.
*/
-import static org.apache.commons.graph.visit.Visit.depthFirstSearch;
+import static org.apache.commons.graph.CommonsGraph.on;
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)
{
- depthFirstSearch( graph, source, new KosarajuSharirVisitHandler<V, E>( source ) );
+ on( graph ).visit().from( source ).applyingDepthFirstSearch( new KosarajuSharirVisitHandler<V, E>( source ) );
DirectedGraph<V, E> reverted = new RevertedGraph<V, E>( graph );
}
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java?rev=1234588&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java Sun Jan 22 20:04:57 2012
@@ -0,0 +1,187 @@
+package org.apache.commons.graph.visit;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.commons.graph.utils.Assertions.checkNotNull;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Queue;
+import java.util.Set;
+import java.util.Stack;
+
+import org.apache.commons.graph.DirectedGraph;
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Vertex;
+
+/**
+ * {@link VisitAlgorithmsSelector} implementation.
+ *
+ * @param <V> the Graph vertices type
+ * @param <E> the Graph edges type
+ * @param <G> the Graph type
+ */
+final class DefaultVisitAlgorithmsSelector<V extends Vertex, E extends Edge, G extends Graph<V, E>>
+ implements VisitAlgorithmsSelector<V, E, G>
+{
+
+ private final G graph;
+
+ private final V source;
+
+ public DefaultVisitAlgorithmsSelector( G graph, V source )
+ {
+ this.graph = graph;
+ this.source = source;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Graph<V, E> applyingBreadthFirstSearch()
+ {
+ VisitGraphBuilder<V, E> visitGraphBuilder = new VisitGraphBuilder<V, E>();
+ applyingBreadthFirstSearch( visitGraphBuilder );
+ return visitGraphBuilder.getVisitGraph();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public Graph<V, E> applyingDepthFirstSearch()
+ {
+ VisitGraphBuilder<V, E> visitGraphBuilder = new VisitGraphBuilder<V, E>();
+ applyingDepthFirstSearch( visitGraphBuilder );
+ return visitGraphBuilder.getVisitGraph();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void applyingBreadthFirstSearch( GraphVisitHandler<V, E> handler )
+ {
+ handler = checkNotNull( handler, "Graph visitor handler can not be null." );
+
+ handler.discoverGraph( graph );
+
+ Queue<V> vertexQueue = new LinkedList<V>();
+ vertexQueue.add( source );
+
+ Set<V> visitedVertices = new HashSet<V>();
+ visitedVertices.add( source );
+
+ boolean visitingGraph = true;
+
+ while ( visitingGraph && !vertexQueue.isEmpty() )
+ {
+ V v = vertexQueue.remove();
+
+ if ( handler.discoverVertex( v ) ) {
+
+ Iterator<V> connected = ( graph instanceof DirectedGraph ) ? ( (DirectedGraph<V, E>) graph ).getOutbound( v ).iterator()
+ : graph.getConnectedVertices( v ).iterator();
+
+ while ( connected.hasNext() )
+ {
+ V w = connected.next();
+ if ( visitedVertices.add( w ) )
+ {
+ E e = graph.getEdge( v, w );
+
+ if ( handler.discoverEdge( v, e, w ) )
+ {
+ vertexQueue.offer( w );
+ }
+
+ if ( handler.finishEdge( v, e, w ) )
+ {
+ visitingGraph = false;
+ }
+ }
+ }
+
+ }
+
+ if ( handler.finishVertex( v ) )
+ {
+ visitingGraph = false;
+ }
+ }
+
+ handler.finishGraph( graph );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void applyingDepthFirstSearch( GraphVisitHandler<V, E> handler )
+ {
+ handler = checkNotNull( handler, "Graph visitor handler can not be null." );
+
+ handler.discoverGraph( graph );
+
+ Stack<V> vertexStack = new Stack<V>();
+ vertexStack.push( source );
+
+ Set<V> visitedVertices = new HashSet<V>();
+ visitedVertices.add( source );
+
+ boolean visitingGraph = true;
+
+ while ( visitingGraph && !vertexStack.isEmpty() )
+ {
+ V v = vertexStack.pop();
+
+ if ( handler.discoverVertex( v ) )
+ {
+ Iterator<V> connected = ( graph instanceof DirectedGraph ) ? ( (DirectedGraph<V, E>) graph ).getOutbound( v ).iterator()
+ : graph.getConnectedVertices( v ).iterator();
+
+ while ( connected.hasNext() )
+ {
+ V w = connected.next();
+ if ( visitedVertices.add( w ) )
+ {
+ E e = graph.getEdge( v, w );
+
+ if ( handler.discoverEdge( v, e, w ) )
+ {
+ vertexStack.push( w );
+ }
+
+ if ( handler.finishEdge( v, e, w ) ) {
+ visitingGraph = false;
+ }
+ }
+ }
+ }
+
+ if ( handler.finishVertex( v ) )
+ {
+ visitingGraph = false;
+ }
+ }
+
+ handler.finishGraph( graph );
+ }
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitSourceSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitSourceSelector.java?rev=1234588&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitSourceSelector.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitSourceSelector.java Sun Jan 22 20:04:57 2012
@@ -0,0 +1,55 @@
+package org.apache.commons.graph.visit;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import static org.apache.commons.graph.utils.Assertions.checkNotNull;
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Vertex;
+
+/**
+ * {@link VisitSourceSelector} implementation.
+ *
+ * @param <V> the Graph vertices type
+ * @param <E> the Graph edges type
+ * @param <G> the Graph type
+ */
+public final class DefaultVisitSourceSelector<V extends Vertex, E extends Edge, G extends Graph<V, E>>
+ implements VisitSourceSelector<V, E, G>
+{
+
+ private final G graph;
+
+ public DefaultVisitSourceSelector( G graph )
+ {
+ this.graph = graph;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public VisitAlgorithmsSelector<V, E, G> from( V source )
+ {
+ source = checkNotNull( source, "Impossible to visit input graph %s with null source", graph );
+ return new DefaultVisitAlgorithmsSelector<V, E, G>( graph, source );
+ }
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitSourceSelector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitSourceSelector.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitSourceSelector.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitAlgorithmsSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitAlgorithmsSelector.java?rev=1234588&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitAlgorithmsSelector.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitAlgorithmsSelector.java Sun Jan 22 20:04:57 2012
@@ -0,0 +1,64 @@
+package org.apache.commons.graph.visit;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Vertex;
+
+/**
+ * Applies different implementations of Graph visitor algorithms.
+ *
+ * @param <V> the Graph vertices type
+ * @param <E> the Graph edges type
+ * @param <G> the Graph type
+ */
+public interface VisitAlgorithmsSelector<V extends Vertex, E extends Edge, G extends Graph<V, E>>
+{
+
+ /**
+ * Breadth-first search algorithm implementation.
+ *
+ * @return the breadth first search tree
+ */
+ Graph<V, E> applyingBreadthFirstSearch();
+
+ /**
+ * Depth-first search algorithm implementation.
+ *
+ * @return the depth first search tree
+ */
+ Graph<V, E> applyingDepthFirstSearch();
+
+ /**
+ * Breadth-first search algorithm implementation.
+ *
+ * @param handler the handler intercepts visit actions
+ */
+ void applyingBreadthFirstSearch( GraphVisitHandler<V, E> handler );
+
+ /**
+ * Depth-first search algorithm implementation.
+ *
+ * @param handler the handler intercepts visit actions
+ */
+ void applyingDepthFirstSearch( GraphVisitHandler<V, E> handler );
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitAlgorithmsSelector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitAlgorithmsSelector.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitAlgorithmsSelector.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitSourceSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitSourceSelector.java?rev=1234588&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitSourceSelector.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitSourceSelector.java Sun Jan 22 20:04:57 2012
@@ -0,0 +1,44 @@
+package org.apache.commons.graph.visit;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Vertex;
+
+/**
+ * Search root node selector.
+ *
+ * @param <V> the Graph vertices type
+ * @param <E> the Graph edges type
+ * @param <G> the Graph type
+ */
+public interface VisitSourceSelector<V extends Vertex, E extends Edge, G extends Graph<V, E>>
+{
+
+ /**
+ * Select the root node the search begins from.
+ *
+ * @param source the root node the search begins from
+ * @return the search visit algorithm selector
+ */
+ VisitAlgorithmsSelector<V, E, G> from( V source );
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitSourceSelector.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitSourceSelector.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitSourceSelector.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
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=1234588&r1=1234587&r2=1234588&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 Sun Jan 22 20:04:57 2012
@@ -19,8 +19,7 @@ package org.apache.commons.graph.visit;
* under the License.
*/
-import static org.apache.commons.graph.visit.Visit.breadthFirstSearch;
-import static org.apache.commons.graph.visit.Visit.depthFirstSearch;
+import static org.apache.commons.graph.CommonsGraph.on;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
@@ -101,7 +100,9 @@ public final class VisitTestCase
// actual graph
- Graph<BaseLabeledVertex, BaseLabeledEdge> actual = breadthFirstSearch( input, s );
+ Graph<BaseLabeledVertex, BaseLabeledEdge> actual = on( input ).visit().from( s ).applyingBreadthFirstSearch();
+
+ // Graph<BaseLabeledVertex, BaseLabeledEdge> actual = breadthFirstSearch( input, s );
// assertion
@@ -172,7 +173,9 @@ public final class VisitTestCase
NodeSequenceVisitor<BaseLabeledVertex, BaseLabeledEdge> visitor =
new NodeSequenceVisitor<BaseLabeledVertex, BaseLabeledEdge>();
- depthFirstSearch( input, s, visitor );
+
+ on( input ).visit().from( s ).applyingDepthFirstSearch( visitor );
+
final List<BaseLabeledVertex> actual = visitor.getVertices();
// assertion