Class AttributedGraph

java.lang.Object
org.jgrapht.graph.AbstractGraph<V,E>
org.jgrapht.graph.AbstractBaseGraph<AttributedVertex,AttributedEdge>
ghidra.service.graph.AttributedGraph
All Implemented Interfaces:
Serializable, 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:
  • Field Details

  • Constructor Details

    • AttributedGraph

      public AttributedGraph(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(String name, GraphType type, 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(String name, GraphType type, 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 Details

    • getName

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

      public String getDescription()
      Returns a description of the graph
      Returns:
      a description of the graph
    • getGraphType

      public GraphType getGraphType()
      Returns the GraphType for this graph
      Returns:
      the GraphType for this graph
    • addVertex

      public AttributedVertex addVertex(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(String id, String vertexName)
      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.
      vertexName - the name to associate with this vertex
      Returns:
      either an existing vertex with that id, or a newly added vertex with that id
    • addVertex

      public AttributedVertex addVertex()
      Specified by:
      addVertex in interface org.jgrapht.Graph<AttributedVertex,AttributedEdge>
      Overrides:
      addVertex in class org.jgrapht.graph.AbstractBaseGraph<AttributedVertex,AttributedEdge>
    • addVertex

      public boolean addVertex(AttributedVertex vertex)
      Specified by:
      addVertex in interface org.jgrapht.Graph<AttributedVertex,AttributedEdge>
      Overrides:
      addVertex in class org.jgrapht.graph.AbstractBaseGraph<AttributedVertex,AttributedEdge>
    • addEdge

      public AttributedEdge addEdge(AttributedVertex source, AttributedVertex target, 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(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