commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From simonetrip...@apache.org
Subject svn commit: r1203666 - /commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectedcomponents/KosarajuSharirVisitHandler.java
Date Fri, 18 Nov 2011 14:31:24 GMT
Author: simonetripodi
Date: Fri Nov 18 14:31:24 2011
New Revision: 1203666

URL: http://svn.apache.org/viewvc?rev=1203666&view=rev
Log:
first checkin of KosarajuSharirVisitHandler class

Added:
    commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectedcomponents/KosarajuSharirVisitHandler.java
  (with props)

Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectedcomponents/KosarajuSharirVisitHandler.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectedcomponents/KosarajuSharirVisitHandler.java?rev=1203666&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectedcomponents/KosarajuSharirVisitHandler.java
(added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectedcomponents/KosarajuSharirVisitHandler.java
Fri Nov 18 14:31:24 2011
@@ -0,0 +1,69 @@
+package org.apache.commons.graph.connectedcomponents;
+
+/*
+ * 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 java.util.LinkedList;
+
+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;
+
+/**
+ * Kosaraju's strongly connected component algorithm is based on DFS (or BFS) algorithm
+ * and needs to execute specific actions during the visit.
+ *
+ * @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 V startVisit;
+
+    public KosarajuSharirVisitHandler( final V startVisit )
+    {
+        this.startVisit = startVisit;
+    }
+
+    final LinkedList<V> vertices = new LinkedList<V>();
+
+    /**
+     * {@inheritDoc}
+     */
+    public void finishVertex( V vertex )
+    {
+        if ( !startVisit.equals( vertex ) )
+        {
+            vertices.add( vertex );
+        }
+    }
+
+    @Override
+    public void finishGraph( Graph<V, E> graph )
+    {
+        vertices.add( startVisit );
+
+        // FIXME make sure the vertices order is the one needed by the algorithm
+        System.out.println( "Visit complete: " + vertices );
+    }
+
+}

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectedcomponents/KosarajuSharirVisitHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectedcomponents/KosarajuSharirVisitHandler.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/connectedcomponents/KosarajuSharirVisitHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message