commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1237632 - in /commons/sandbox/graph/trunk/src: changes/ main/java/org/apache/commons/graph/flow/ main/java/org/apache/commons/graph/scc/ main/java/org/apache/commons/graph/visit/ test/java/org/apache/commons/graph/visit/
Date Mon, 30 Jan 2012 13:03:32 GMT
Author: simonetripodi
Date: Mon Jan 30 13:03:31 2012
New Revision: 1237632

URL: http://svn.apache.org/viewvc?rev=1237632&view=rev
Log:
[SANDBOX-372] Make the org.apache.commons.graph.visit.GraphVisitHandler able to return objects

Modified:
    commons/sandbox/graph/trunk/src/changes/changes.xml
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/DefaultMaxFlowAlgorithmSelector.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/FlowNetworkHandler.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/DefaultSccAlgorithmSelector.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/KosarajuSharirVisitHandler.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/BaseGraphVisitHandler.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/GraphVisitHandler.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitAlgorithmsSelector.java
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitGraphBuilder.java
    commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/visit/NodeSequenceVisitor.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=1237632&r1=1237631&r2=1237632&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/changes/changes.xml (original)
+++ commons/sandbox/graph/trunk/src/changes/changes.xml Mon Jan 30 13:03:31 2012
@@ -23,6 +23,9 @@
   </properties>
   <body>
   <release version="0.1" date="201?-??-??" description="First release.">
+    <action dev="simonetripodi" type="update" issue="SANDBOX-372">
+      Make the org.apache.commons.graph.visit.GraphVisitHandler able to return objects
+    </action>
     <action dev="simonetripodi" type="add" issue="SANDBOX-370" due-to="Matteo Moci">
       GraphML format exporter
     </action>

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/DefaultMaxFlowAlgorithmSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/DefaultMaxFlowAlgorithmSelector.java?rev=1237632&r1=1237631&r2=1237632&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/DefaultMaxFlowAlgorithmSelector.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/DefaultMaxFlowAlgorithmSelector.java
Mon Jan 30 13:03:31 2012
@@ -95,8 +95,7 @@ final class DefaultMaxFlowAlgorithmSelec
         } );
 
         // create flow network handler
-        FlowNetworkHandler<V, WeightedEdge<W>, W> flowNetworkHandler =
-                        new FlowNetworkHandler<V, WeightedEdge<W>, W>( flowNetwork,
source, target, monoid );
+        FlowNetworkHandler<V, W> flowNetworkHandler = new FlowNetworkHandler<V,
W>( flowNetwork, source, target, monoid );
 
         // perform depth first search
         visit( flowNetwork ).from( source ).applyingDepthFirstSearch( flowNetworkHandler
);
@@ -109,7 +108,7 @@ final class DefaultMaxFlowAlgorithmSelec
             visit( flowNetwork ).from( source ).applyingDepthFirstSearch( flowNetworkHandler
);
         }
 
-        return flowNetworkHandler.getMaxFlow();
+        return flowNetworkHandler.onCompleted();
     }
 
     /**

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/FlowNetworkHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/FlowNetworkHandler.java?rev=1237632&r1=1237631&r2=1237632&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/FlowNetworkHandler.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/flow/FlowNetworkHandler.java
Mon Jan 30 13:03:31 2012
@@ -23,7 +23,6 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.graph.DirectedGraph;
-import org.apache.commons.graph.Graph;
 import org.apache.commons.graph.Vertex;
 import org.apache.commons.graph.VertexPair;
 import org.apache.commons.graph.WeightedEdge;
@@ -40,11 +39,11 @@ import org.apache.commons.graph.weight.O
  * @param <WE> the weighted edge type
  * @param <W> the weight type
  */
-class FlowNetworkHandler<V extends Vertex, WE extends WeightedEdge<W>, W>
-    extends BaseGraphVisitHandler<V, WE>
+class FlowNetworkHandler<V extends Vertex, W>
+    extends BaseGraphVisitHandler<V, WeightedEdge<W>, DirectedGraph<V, WeightedEdge<W>>,
W>
 {
 
-    private final DirectedGraph<V, WE> flowNetwork;
+    private final DirectedGraph<V, WeightedEdge<W>> flowNetwork;
 
     private final V source;
 
@@ -54,14 +53,14 @@ class FlowNetworkHandler<V extends Verte
 
     private W maxFlow;
 
-    private final Map<WE, W> residualEdgeCapacities = new HashMap<WE, W>();
+    private final Map<WeightedEdge<W>, W> residualEdgeCapacities = new HashMap<WeightedEdge<W>,
W>();
 
     // these are new for each new visit of the graph
-    private PredecessorsList<V, WE, W> predecessors;
+    private PredecessorsList<V, WeightedEdge<W>, W> predecessors;
 
     private boolean foundAugmentingPath;
 
-    FlowNetworkHandler( DirectedGraph<V, WE> flowNetwork, V source, V target, OrderedMonoid<W>
orderedMonoid )
+    FlowNetworkHandler( DirectedGraph<V, WeightedEdge<W>> flowNetwork, V source,
V target, OrderedMonoid<W> orderedMonoid )
     {
         this.flowNetwork = flowNetwork;
         this.source = source;
@@ -70,7 +69,7 @@ class FlowNetworkHandler<V extends Verte
 
         maxFlow = orderedMonoid.zero();
 
-        for ( WE edge : flowNetwork.getEdges() )
+        for ( WeightedEdge<W> edge : flowNetwork.getEdges() )
         {
             residualEdgeCapacities.put( edge, edge.getWeight() );
         }
@@ -95,11 +94,11 @@ class FlowNetworkHandler<V extends Verte
     void updateResidualNetworkWithCurrentAugmentingPath()
     {
         // build actual augmenting path
-        WeightedPath<V, WE, W> augmentingPath = predecessors.buildPath( source, target
);
+        WeightedPath<V, WeightedEdge<W>, W> augmentingPath = predecessors.buildPath(
source, target );
 
         // find flow increment
         W flowIncrement = null;
-        for ( WE edge : augmentingPath.getEdges() )
+        for ( WeightedEdge<W> edge : augmentingPath.getEdges() )
         {
             W edgeCapacity = residualEdgeCapacities.get( edge );
             if ( flowIncrement == null
@@ -111,7 +110,7 @@ class FlowNetworkHandler<V extends Verte
 
         // update max flow and capacities accordingly
         maxFlow = orderedMonoid.append( maxFlow, flowIncrement );
-        for ( WE edge : augmentingPath.getEdges() )
+        for ( WeightedEdge<W> edge : augmentingPath.getEdges() )
         {
             // decrease capacity for direct edge
             W directCapacity = residualEdgeCapacities.get( edge );
@@ -119,29 +118,20 @@ class FlowNetworkHandler<V extends Verte
 
             // increase capacity for inverse edge
             VertexPair<V> vertexPair = flowNetwork.getVertices( edge );
-            WE inverseEdge = flowNetwork.getEdge( vertexPair.getTail(), vertexPair.getHead()
);
+            WeightedEdge<W> inverseEdge = flowNetwork.getEdge( vertexPair.getTail(),
vertexPair.getHead() );
             W inverseCapacity = residualEdgeCapacities.get( inverseEdge );
             residualEdgeCapacities.put( inverseEdge, orderedMonoid.append( inverseCapacity,
flowIncrement ) );
         }
     }
 
     /**
-     * Returns the maximum flow through the input graph.
-     * @return the maximum flow through the input graph
-     */
-    W getMaxFlow()
-    {
-        return maxFlow;
-    }
-
-    /**
      * {@inheritDoc}
      */
     @Override
-    public void discoverGraph( Graph<V, WE> graph )
+    public void discoverGraph( DirectedGraph<V, WeightedEdge<W>> graph )
     {
         // reset ausiliary structures for a new graph visit
-        predecessors = new PredecessorsList<V, WE, W>( graph, orderedMonoid );
+        predecessors = new PredecessorsList<V, WeightedEdge<W>, W>( graph, orderedMonoid
);
         foundAugmentingPath = false;
     }
 
@@ -149,7 +139,7 @@ class FlowNetworkHandler<V extends Verte
      * {@inheritDoc}
      */
     @Override
-    public boolean discoverEdge( V head, WE edge, V tail )
+    public boolean discoverEdge( V head, WeightedEdge<W> edge, V tail )
     {
         W residualEdgeCapacity = residualEdgeCapacities.get( edge );
         // avoid expanding the edge when it has no residual capacity
@@ -165,7 +155,7 @@ class FlowNetworkHandler<V extends Verte
      * {@inheritDoc}
      */
     @Override
-    public boolean finishEdge( V head, WE edge, V tail )
+    public boolean finishEdge( V head, WeightedEdge<W> edge, V tail )
     {
         if ( tail.equals( target ) )
         {
@@ -176,4 +166,10 @@ class FlowNetworkHandler<V extends Verte
         return false;
     }
 
+    @Override
+    public W onCompleted()
+    {
+        return maxFlow;
+    }
+
 }

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=1237632&r1=1237631&r2=1237632&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 30 13:03:31 2012
@@ -38,11 +38,11 @@ import org.apache.commons.graph.visit.Ba
  * @param <V> the Graph vertices type.
  * @param <E> the Graph edges type.
  */
-final class CheriyanMehlhornGabowVisitHandler<V extends Vertex, E extends Edge>
-    extends BaseGraphVisitHandler<V, E>
+final class CheriyanMehlhornGabowVisitHandler<V extends Vertex, E extends Edge, G extends
DirectedGraph<V, E>>
+    extends BaseGraphVisitHandler<V, E, G, Void>
 {
 
-    private final DirectedGraph<V, E> graph;
+    private final G graph;
 
     private final Map<V, Integer> preorder = new HashMap<V, Integer>();
 
@@ -58,7 +58,7 @@ final class CheriyanMehlhornGabowVisitHa
 
     private int sscCounter = 0;
 
-    public CheriyanMehlhornGabowVisitHandler( DirectedGraph<V, E> graph, Set<V>
marked )
+    public CheriyanMehlhornGabowVisitHandler( G graph, Set<V> marked )
     {
         this.graph = graph;
         this.marked = marked;

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/DefaultSccAlgorithmSelector.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/DefaultSccAlgorithmSelector.java?rev=1237632&r1=1237631&r2=1237632&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/DefaultSccAlgorithmSelector.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/DefaultSccAlgorithmSelector.java
Mon Jan 30 13:03:31 2012
@@ -61,7 +61,7 @@ public final class DefaultSccAlgorithmSe
     {
         source = checkNotNull( source, "KosarajuSharir algorithm requires a non-null source
vertex" );
 
-        visit( graph ).from( source ).applyingDepthFirstSearch( new KosarajuSharirVisitHandler<V,
E>( source ) );
+        visit( graph ).from( source ).applyingDepthFirstSearch( new KosarajuSharirVisitHandler<V,
E, G>( source ) );
 
         DirectedGraph<V, E> reverted = new RevertedGraph<V, E>( graph );
 
@@ -77,7 +77,7 @@ public final class DefaultSccAlgorithmSe
     {
         final Set<V> marked = new HashSet<V>();
 
-        final GraphVisitHandler<V, E> visitHandler = new CheriyanMehlhornGabowVisitHandler<V,
E>( graph, marked );
+        final GraphVisitHandler<V, E, G, Void> visitHandler = new CheriyanMehlhornGabowVisitHandler<V,
E, G>( graph, marked );
 
         for ( V vertex : graph.getVertices() )
         {

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/KosarajuSharirVisitHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/KosarajuSharirVisitHandler.java?rev=1237632&r1=1237631&r2=1237632&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/KosarajuSharirVisitHandler.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/scc/KosarajuSharirVisitHandler.java
Mon Jan 30 13:03:31 2012
@@ -21,8 +21,8 @@ package org.apache.commons.graph.scc;
 
 import java.util.LinkedList;
 
+import org.apache.commons.graph.DirectedGraph;
 import org.apache.commons.graph.Edge;
-import org.apache.commons.graph.Graph;
 import org.apache.commons.graph.Vertex;
 import org.apache.commons.graph.visit.BaseGraphVisitHandler;
 
@@ -33,8 +33,8 @@ import org.apache.commons.graph.visit.Ba
  * @param <V> the Graph vertices type.
  * @param <E> the Graph edges type.
  */
-final class KosarajuSharirVisitHandler<V extends Vertex, E extends Edge>
-    extends BaseGraphVisitHandler<V, E>
+final class KosarajuSharirVisitHandler<V extends Vertex, E extends Edge, G extends DirectedGraph<V,
E>>
+    extends BaseGraphVisitHandler<V, E, G, Void>
 {
 
     final V startVisit;
@@ -59,7 +59,7 @@ final class KosarajuSharirVisitHandler<V
     }
 
     @Override
-    public void finishGraph( Graph<V, E> graph )
+    public void finishGraph( G graph )
     {
         vertices.add( startVisit );
 

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/BaseGraphVisitHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/BaseGraphVisitHandler.java?rev=1237632&r1=1237631&r2=1237632&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/BaseGraphVisitHandler.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/BaseGraphVisitHandler.java
Mon Jan 30 13:03:31 2012
@@ -29,14 +29,14 @@ import org.apache.commons.graph.Vertex;
  * @param <V> the Graph vertices type
  * @param <E> the Graph edges type
  */
-public class BaseGraphVisitHandler<V extends Vertex, E extends Edge>
-    implements GraphVisitHandler<V, E>
+public class BaseGraphVisitHandler<V extends Vertex, E extends Edge, G extends Graph<V,
E>, O>
+    implements GraphVisitHandler<V, E, G, O>
 {
 
     /**
      * {@inheritDoc}
      */
-    public void discoverGraph( Graph<V, E> graph )
+    public void discoverGraph( G graph )
     {
         // do nothing
     }
@@ -80,9 +80,17 @@ public class BaseGraphVisitHandler<V ext
     /**
      * {@inheritDoc}
      */
-    public void finishGraph( Graph<V, E> graph )
+    public void finishGraph( G graph )
     {
         // do nothing
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    public O onCompleted()
+    {
+        return null;
+    }
+
 }

Modified: 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=1237632&r1=1237631&r2=1237632&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/DefaultVisitAlgorithmsSelector.java
Mon Jan 30 13:03:31 2012
@@ -59,9 +59,7 @@ final class DefaultVisitAlgorithmsSelect
      */
     public Graph<V, E> applyingBreadthFirstSearch()
     {
-        VisitGraphBuilder<V, E> visitGraphBuilder = new VisitGraphBuilder<V, E>();
-        applyingBreadthFirstSearch( visitGraphBuilder );
-        return visitGraphBuilder.getVisitGraph();
+        return applyingBreadthFirstSearch( new VisitGraphBuilder<V, E, G>() );
     }
 
     /**
@@ -69,15 +67,13 @@ final class DefaultVisitAlgorithmsSelect
      */
     public Graph<V, E> applyingDepthFirstSearch()
     {
-        VisitGraphBuilder<V, E> visitGraphBuilder = new VisitGraphBuilder<V, E>();
-        applyingDepthFirstSearch( visitGraphBuilder );
-        return visitGraphBuilder.getVisitGraph();
+        return applyingDepthFirstSearch( new VisitGraphBuilder<V, E, G>() );
     }
 
     /**
      * {@inheritDoc}
      */
-    public void applyingBreadthFirstSearch( GraphVisitHandler<V, E> handler )
+    public <O> O applyingBreadthFirstSearch( GraphVisitHandler<V, E, G, O> handler
)
     {
         handler = checkNotNull( handler, "Graph visitor handler can not be null." );
 
@@ -128,12 +124,14 @@ final class DefaultVisitAlgorithmsSelect
         }
 
         handler.finishGraph( graph );
+
+        return handler.onCompleted();
     }
 
     /**
      * {@inheritDoc}
      */
-    public void applyingDepthFirstSearch( GraphVisitHandler<V, E> handler )
+    public <O> O applyingDepthFirstSearch( GraphVisitHandler<V, E, G, O> handler
)
     {
         handler = checkNotNull( handler, "Graph visitor handler can not be null." );
 
@@ -182,6 +180,8 @@ final class DefaultVisitAlgorithmsSelect
         }
 
         handler.finishGraph( graph );
+
+        return handler.onCompleted();
     }
 
 }

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/GraphVisitHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/GraphVisitHandler.java?rev=1237632&r1=1237631&r2=1237632&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/GraphVisitHandler.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/GraphVisitHandler.java
Mon Jan 30 13:03:31 2012
@@ -27,13 +27,13 @@ import org.apache.commons.graph.Vertex;
  * A {@link GraphVisitHandler} controls the execution of breadth-first and depth-first search
  * algorithms in {@link Visit}.
  */
-public interface GraphVisitHandler<V extends Vertex, E extends Edge>
+public interface GraphVisitHandler<V extends Vertex, E extends Edge, G extends Graph<V,
E>, O>
 {
 
     /**
      * Called at the beginning of breadth-first and depth-first search.
      */
-    void discoverGraph( Graph<V, E> graph );
+    void discoverGraph( G graph );
 
     /**
      * Performs operations on the input {@link Vertex} and checks if it should be expanded
@@ -66,6 +66,13 @@ public interface GraphVisitHandler<V ext
     /**
      * Called upon termination of the search algorithm.
      */
-    void finishGraph( Graph<V, E> graph );
+    void finishGraph( G graph );
+
+    /**
+     * Invoked once the visit is finished.
+     *
+     * @return Value that will be returned by the visit
+     */
+    O onCompleted();
 
 }

Modified: 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=1237632&r1=1237631&r2=1237632&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitAlgorithmsSelector.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitAlgorithmsSelector.java
Mon Jan 30 13:03:31 2012
@@ -52,13 +52,13 @@ public interface VisitAlgorithmsSelector
      *
      * @param handler the handler intercepts visit actions
      */
-    void applyingBreadthFirstSearch( GraphVisitHandler<V, E> handler );
+    <O> O applyingBreadthFirstSearch( GraphVisitHandler<V, E, G, O> handler );
 
     /**
      * Depth-first search algorithm implementation.
      *
      * @param handler the handler intercepts visit actions
      */
-    void applyingDepthFirstSearch( GraphVisitHandler<V, E> handler );
+    <O> O applyingDepthFirstSearch( GraphVisitHandler<V, E, G, O> handler );
 
 }

Modified: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitGraphBuilder.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitGraphBuilder.java?rev=1237632&r1=1237631&r2=1237632&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitGraphBuilder.java
(original)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitGraphBuilder.java
Mon Jan 30 13:03:31 2012
@@ -33,8 +33,8 @@ import org.apache.commons.graph.model.Un
  * @param <V> the Graph vertices type.
  * @param <E> the Graph edges type.
  */
-final class VisitGraphBuilder<V extends Vertex, E extends Edge>
-    extends BaseGraphVisitHandler<V, E>
+final class VisitGraphBuilder<V extends Vertex, E extends Edge, G extends Graph<V,
E>>
+    extends BaseGraphVisitHandler<V, E, G, Graph<V, E>>
 {
 
     private BaseMutableGraph<V, E> visitGraph;
@@ -43,7 +43,7 @@ final class VisitGraphBuilder<V extends 
      * {@inheritDoc}
      */
     @Override
-    public void discoverGraph( Graph<V, E> graph )
+    public void discoverGraph( G graph )
     {
         if ( graph instanceof DirectedGraph )
         {
@@ -71,11 +71,10 @@ final class VisitGraphBuilder<V extends 
     }
 
     /**
-     * Returns the produced visit Graph.
-     *
-     * @return the produced visit Graph.
+     * {@inheritDoc}
      */
-    public Graph<V, E> getVisitGraph()
+    @Override
+    public Graph<V, E> onCompleted()
     {
         return visitGraph;
     }

Modified: commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/visit/NodeSequenceVisitor.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/visit/NodeSequenceVisitor.java?rev=1237632&r1=1237631&r2=1237632&view=diff
==============================================================================
--- commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/visit/NodeSequenceVisitor.java
(original)
+++ commons/sandbox/graph/trunk/src/test/java/org/apache/commons/graph/visit/NodeSequenceVisitor.java
Mon Jan 30 13:03:31 2012
@@ -24,31 +24,31 @@ import static java.util.Collections.unmo
 import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.commons.graph.Edge;
-import org.apache.commons.graph.Vertex;
+import org.apache.commons.graph.model.BaseLabeledEdge;
+import org.apache.commons.graph.model.BaseLabeledVertex;
+import org.apache.commons.graph.model.UndirectedMutableGraph;
 
-public final class NodeSequenceVisitor<V extends Vertex, E extends Edge>
-    extends BaseGraphVisitHandler<V, E>
+public final class NodeSequenceVisitor
+    extends BaseGraphVisitHandler<BaseLabeledVertex, BaseLabeledEdge, UndirectedMutableGraph<BaseLabeledVertex,
BaseLabeledEdge>, List<BaseLabeledVertex>>
 {
 
-    private final List<V> vertices = new ArrayList<V>();
+    private final List<BaseLabeledVertex> vertices = new ArrayList<BaseLabeledVertex>();
 
     /**
      * {@inheritDoc}
      */
     @Override
-    public boolean discoverVertex( V vertex )
+    public boolean discoverVertex( BaseLabeledVertex vertex )
     {
         vertices.add( vertex );
         return true;
     }
 
     /**
-     * 
-     *
-     * @return
+     * {@inheritDoc}
      */
-    public List<V> getVertices()
+    @Override
+    public List<BaseLabeledVertex> onCompleted()
     {
         return unmodifiableList( vertices );
     }

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=1237632&r1=1237631&r2=1237632&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 30 13:03:31 2012
@@ -177,12 +177,8 @@ public final class VisitTestCase
 
         // actual node set
 
-        NodeSequenceVisitor<BaseLabeledVertex, BaseLabeledEdge> visitor =
-            new NodeSequenceVisitor<BaseLabeledVertex, BaseLabeledEdge>();
-
-        visit( input ).from( new BaseLabeledVertex( "S" ) ).applyingDepthFirstSearch( visitor
);
-
-        final List<BaseLabeledVertex> actual = visitor.getVertices();
+        final List<BaseLabeledVertex> actual =
+            visit( input ).from( new BaseLabeledVertex( "S" ) ).applyingDepthFirstSearch(
new NodeSequenceVisitor() );
 
         // assertion
 



Mime
View raw message