Author: simonetripodi
Date: Sat Jun 18 10:46:18 2011
New Revision: 1137161
URL: http://svn.apache.org/viewvc?rev=1137161&view=rev
Log:
first checkin of VisitGraphBuilder class
Added:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitGraphBuilder.java
(with props)
Added:
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=1137161&view=auto
==============================================================================
---
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitGraphBuilder.java
(added)
+++
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitGraphBuilder.java
Sat Jun 18 10:46:18 2011
@@ -0,0 +1,82 @@
+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.DirectedGraph;
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Vertex;
+import org.apache.commons.graph.model.BaseMutableGraph;
+import org.apache.commons.graph.model.DirectedMutableGraph;
+import org.apache.commons.graph.model.UndirectedMutableGraph;
+
+/**
+ * Internal Visitor helper that produces the search tree.
+ *
+ * @param <V> the Graph vertices type.
+ * @param <E> the Graph edges type.
+ */
+final class VisitGraphBuilder<V extends Vertex, E extends Edge<V>>
+ extends BaseGraphVisitHandler<V, E>
+{
+
+ private BaseMutableGraph<V, E> visitGraph;
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void discoverGraph( Graph<V, E> graph )
+ {
+ if ( graph instanceof DirectedGraph )
+ {
+ visitGraph = new DirectedMutableGraph<V, E>();
+ }
+ else
+ {
+ visitGraph = new UndirectedMutableGraph<V, E>();
+ }
+
+ for ( V vertex : graph.getVertices() )
+ {
+ visitGraph.addVertex( vertex );
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void discoverEdge( E edge )
+ {
+ visitGraph.addEdge( edge );
+ }
+
+ /**
+ * Returns the produced visit Graph.
+ *
+ * @return the produced visit Graph.
+ */
+ public Graph<V, E> getVisitGraph()
+ {
+ return visitGraph;
+ }
+
+}
Propchange:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitGraphBuilder.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitGraphBuilder.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/visit/VisitGraphBuilder.java
------------------------------------------------------------------------------
svn:mime-type = text/plain