title: Implementing Graph as a map of maps
body: <p>I am implementing the graph data structure in Java as a Map of maps. </p>
  
  <p>The Graph object is a map of data(key) and all vertices(value)</p>
  
  <pre><code>public class GraphAdjMap&lt;T&gt; implements IGraph&lt;T&gt; {
  
  private Map&lt;T, Vertex&lt;T&gt;&gt; vertices = new HashMap&lt;T, Vertex&lt;T&gt;&gt;(); 
  </code></pre>
  
  <p>Each vertex is a map of edges where key is the destination vertex and value is the edge object:</p>
  
  <pre><code>class Vertex&lt;T&gt; {
  
  private T data;
  private Map&lt;T, Edge&lt;T&gt;&gt; edges = new HashMap&lt;T, Edge&lt;T&gt;&gt;(); 
  </code></pre>
  
  <p>Edge is a simple value object:</p>
  
  <pre><code>public class Edge&lt;T&gt; {  
      private T destination;
      private int weight;
  </code></pre>
  
  <p>With this structure its easy and fast for me to answer a lot of queries like:
  Are 2 edges connected?
  What are all the edges of a vertex?
  Is this vertex connected to the other vertex?
  How many edges does a vertex have?
  etc...</p>
  
  <p>Is this a good implementation or am I missing something?</p>
  
  <p>Thanks,
  Chris.</p>