Class AttributedGraph

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, org.jgrapht.Graph<AttributedVertex,​AttributedEdge>

    public class AttributedGraph
    extends org.jgrapht.graph.AbstractBaseGraph<AttributedVertex,​AttributedEdge>
    Basic graph implementation for a directed graph whose vertices and edges support attributes.

    The graph can be configured as to how to handle multiple edges with the same source and destination vertices. One option is to simply allow multiple edges. The second option is to collapse duplicate edges such that there is only ever one edge with the same source and destination. In this case, each additional duplicate edge added will cause the edge to have a "Weight" attribute that will be the total number of edges that were added to the same source/destination vertex pair.

    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String WEIGHT  
      • Fields inherited from interface org.jgrapht.Graph

        DEFAULT_EDGE_WEIGHT
    • Constructor Summary

      Constructors 
      Constructor Description
      AttributedGraph​(java.lang.String name, GraphType type)
      Create a new empty AttributedGraph that automatically collapses duplicate edges
      AttributedGraph​(java.lang.String name, GraphType type, java.lang.String description)
      Create a new empty AttributedGraph that automatically collapses duplicate edges
      AttributedGraph​(java.lang.String name, GraphType type, java.lang.String description, boolean collapseDuplicateEdges)
      Create a new empty AttributedGraph.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      AttributedEdge addEdge​(AttributedVertex source, AttributedVertex target)
      Creates and adds a new directed edge between the given source and target vertices.
      boolean addEdge​(AttributedVertex source, AttributedVertex target, AttributedEdge edge)
      Creates and adds a new directed edge with the given edge object.
      AttributedEdge addEdge​(AttributedVertex source, AttributedVertex target, java.lang.String edgeId)
      Creates and adds a new directed edge with the given id between the given source and target vertices.
      AttributedVertex addVertex()  
      boolean addVertex​(AttributedVertex vertex)  
      AttributedVertex addVertex​(java.lang.String id)
      Adds a new vertex with the given id.
      AttributedVertex addVertex​(java.lang.String id, java.lang.String name)
      Adds a new vertex with the given id and name.
      java.lang.String getDescription()
      Returns a description of the graph
      int getEdgeCount()
      Returns the total number of edges in the graph
      GraphType getGraphType()
      Returns the GraphType for this graph
      java.lang.String getName()
      Returns the name of the graph
      AttributedVertex getVertex​(java.lang.String vertexId)
      Returns the vertex with the given vertex id
      int getVertexCount()
      Returns the total number of vertices in the graph
      • Methods inherited from class org.jgrapht.graph.AbstractBaseGraph

        clone, containsEdge, containsVertex, degreeOf, edgeSet, edgesOf, getAllEdges, getEdge, getEdgeSource, getEdgeSupplier, getEdgeTarget, getEdgeWeight, getType, getVertexSupplier, incomingEdgesOf, inDegreeOf, iterables, outDegreeOf, outgoingEdgesOf, removeEdge, removeEdge, removeVertex, setEdgeSupplier, setEdgeWeight, setVertexSupplier, vertexSet
      • Methods inherited from class org.jgrapht.graph.AbstractGraph

        assertVertexExist, containsEdge, equals, hashCode, removeAllEdges, removeAllEdges, removeAllEdges, removeAllVertices, toString, toStringFromSets
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.jgrapht.Graph

        containsEdge, removeAllEdges, removeAllEdges, removeAllVertices, setEdgeWeight
    • Constructor Detail

      • AttributedGraph

        public AttributedGraph​(java.lang.String name,
                               GraphType type)
        Create a new empty AttributedGraph that automatically collapses duplicate edges
        Parameters:
        name - the name of the graph
        type - the GraphType which defines valid vertex and edge types.
      • AttributedGraph

        public AttributedGraph​(java.lang.String name,
                               GraphType type,
                               java.lang.String description)
        Create a new empty AttributedGraph that automatically collapses duplicate edges
        Parameters:
        name - the name of the graph
        type - the GraphType which defines valid vertex and edge types.
        description - a description of the graph
      • AttributedGraph

        public AttributedGraph​(java.lang.String name,
                               GraphType type,
                               java.lang.String description,
                               boolean collapseDuplicateEdges)
        Create a new empty AttributedGraph.
        Parameters:
        name - the name of the graph
        type - the GraphType which defines valid vertex and edge types.
        description - a description of the graph
        collapseDuplicateEdges - if true, duplicate edges will be collapsed into a single edge with a "Weight" attribute whose value is the number of edges between those vertices.
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns the name of the graph
        Returns:
        the name of the graph
      • getDescription

        public java.lang.String getDescription()
        Returns a description of the graph
        Returns:
        a description of the graph
      • addVertex

        public AttributedVertex addVertex​(java.lang.String id)
        Adds a new vertex with the given id. The vertex's name will be the same as the id. If a vertex already exists with that id, then that vertex will be returned.
        Parameters:
        id - the unique vertex id that the graph should have a vertex for.
        Returns:
        either an existing vertex with that id, or a newly added vertex with that id
      • addVertex

        public AttributedVertex addVertex​(java.lang.String id,
                                          java.lang.String name)
        Adds a new vertex with the given id and name. If a vertex already exists with that id, then that vertex will be returned, but with its name changed to the given name.
        Parameters:
        id - the unique vertex id that the graph should have a vertex for.
        name - the name to associate with this vertex
        Returns:
        either an existing vertex with that id, or a newly added vertex with that id
      • addEdge

        public AttributedEdge addEdge​(AttributedVertex source,
                                      AttributedVertex target,
                                      java.lang.String edgeId)
        Creates and adds a new directed edge with the given id between the given source and target vertices. If the graph is set to collapse duplicate edges and an edge for that source and target exists, then the existing edge will be return with its "Weight" attribute set to the total number of edges that have been added between the source and target vertices.
        Parameters:
        source - the source vertex of the directed edge to be created.
        target - the target vertex of the directed edge to be created.
        edgeId - the id to use for the new edge. Note: if this is a duplicate and edges are being collapsed, then this edgeId will not be used.
        Returns:
        a new edge between the source and target if it is the first one or the graph is not collapsing edges. Otherwise, an existing edge with its "Weight" attribute set accordingly.
      • addEdge

        public boolean addEdge​(AttributedVertex source,
                               AttributedVertex target,
                               AttributedEdge edge)
        Creates and adds a new directed edge with the given edge object. If the graph is set to collapse duplicate edges and an edge for that source and target exists, then the existing edge will be return with its "Weight" attribute set to the total number of edges that have been added between the source and target vertices.
        Specified by:
        addEdge in interface org.jgrapht.Graph<AttributedVertex,​AttributedEdge>
        Overrides:
        addEdge in class org.jgrapht.graph.AbstractBaseGraph<AttributedVertex,​AttributedEdge>
        Parameters:
        source - the source vertex of the directed edge to be created.
        target - the target vertex of the directed edge to be created.
        edge - the BasicEdge object to use for the new edge. Note: if this is a duplicate and edges are being collapsed, then this edge object will not be used.
        Returns:
        true if the edge was added. Note that if this graph is collapsing duplicate edges, then it will always return true.
      • addEdge

        public AttributedEdge addEdge​(AttributedVertex source,
                                      AttributedVertex target)
        Creates and adds a new directed edge between the given source and target vertices. If the graph is set to collapse duplicate edges and an edge for that source and target exists, then the existing edge will be return with its "Weight" attribute set to the total number of edges that have been added between the source and target vertices.
        Specified by:
        addEdge in interface org.jgrapht.Graph<AttributedVertex,​AttributedEdge>
        Overrides:
        addEdge in class org.jgrapht.graph.AbstractBaseGraph<AttributedVertex,​AttributedEdge>
        Parameters:
        source - the source vertex of the directed edge to be created.
        target - the target vertex of the directed edge to be created.
        Returns:
        a new edge between the source and target if it is the first one or the graph is not collapsing edges. Otherwise, an existing edge with its "Weight" attribute set accordingly.
      • getEdgeCount

        public int getEdgeCount()
        Returns the total number of edges in the graph
        Returns:
        the total number of edges in the graph
      • getVertexCount

        public int getVertexCount()
        Returns the total number of vertices in the graph
        Returns:
        the total number of vertices in the graph
      • getVertex

        public AttributedVertex getVertex​(java.lang.String vertexId)
        Returns the vertex with the given vertex id
        Parameters:
        vertexId - the id of the vertex to retrieve
        Returns:
        the vertex with the given vertex id or null if none found