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 2011/06/15 18:22:47 UTC
svn commit: r1136107 -
/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java
Author: simonetripodi
Date: Wed Jun 15 16:22:47 2011
New Revision: 1136107
URL: http://svn.apache.org/viewvc?rev=1136107&view=rev
Log:
first checkin of BaseGraph, an abstract memory-based Graph representation
in-memory based implementation can be inherit from this class
Added:
commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java (with props)
Added: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java
URL: http://svn.apache.org/viewvc/commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java?rev=1136107&view=auto
==============================================================================
--- commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java (added)
+++ commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java Wed Jun 15 16:22:47 2011
@@ -0,0 +1,107 @@
+package org.apache.commons.graph.model;
+
+/*
+ * 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 java.util.Collections.unmodifiableSet;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.commons.graph.Edge;
+import org.apache.commons.graph.Graph;
+import org.apache.commons.graph.Vertex;
+
+/**
+ * Basic abstract in-memory based of a simple read-only {@link Graph} implementation.
+ *
+ * Subclasses may load adjacency list/edges set in the constructor,
+ * or expose {@link org.apache.commons.graph.MutableGraph} APIs.
+ *
+ * @param <V> the Graph vertices type
+ * @param <E> the Graph edges type
+ */
+public abstract class BaseGraph<V extends Vertex, E extends Edge<V>>
+ implements Graph<V, E>
+{
+
+ private final Map<V, Set<E>> adjacencyList = new HashMap<V, Set<E>>();
+
+ private final Set<E> allEdges = new HashSet<E>();
+
+ /**
+ * {@inheritDoc}
+ */
+ public final Set<V> getVertices()
+ {
+ return unmodifiableSet( adjacencyList.keySet() );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public final Set<E> getEdges()
+ {
+ return unmodifiableSet( allEdges );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public final Set<E> getEdges( V v )
+ {
+ return unmodifiableSet( adjacencyList.get( v ) );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public final Set<V> getVertices( E e )
+ {
+ Set<V> vertices = new HashSet<V>();
+
+ vertices.add( e.getHead() );
+ vertices.add( e.getTail() );
+
+ return unmodifiableSet( vertices );
+ }
+
+ /**
+ * Returns the adjacency list where stored vertex/edges.
+ *
+ * @return the adjacency list where stored vertex/edges.
+ */
+ protected final Map<V, Set<E>> getAdjacencyList()
+ {
+ return adjacencyList;
+ }
+
+ /**
+ * Returns the set with all Graph edges.
+ *
+ * @return the set with all Graph edges.
+ */
+ protected final Set<E> getAllEdges()
+ {
+ return allEdges;
+ }
+
+}
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange: commons/sandbox/graph/trunk/src/main/java/org/apache/commons/graph/model/BaseGraph.java
------------------------------------------------------------------------------
svn:mime-type = text/plain