Package org.insa.graphs.model
Class Graph
java.lang.Object
org.insa.graphs.model.Graph
public final class Graph
extends java.lang.Object
Main graph class.
This class acts as a object-oriented adjacency list for a graph, i.e., it holds a list of nodes and each node holds a list of its successors.
-
Constructor Summary
Constructors Constructor Description Graph(java.lang.String mapId, java.lang.String mapName, java.util.List<Node> nodes, GraphStatistics graphStatistics)
Create a new graph with the given ID, name, nodes and information. -
Method Summary
Modifier and Type Method Description Node
get(int id)
Fetch the node with the given ID.GraphStatistics
getGraphInformation()
java.lang.String
getMapId()
java.lang.String
getMapName()
java.util.List<Node>
getNodes()
int
size()
java.lang.String
toString()
Graph
transpose()
-
Constructor Details
-
Graph
public Graph(java.lang.String mapId, java.lang.String mapName, java.util.List<Node> nodes, GraphStatistics graphStatistics)Create a new graph with the given ID, name, nodes and information.- Parameters:
mapId
- ID of the map corresponding to this graph.mapName
- Name of the map corresponding to this graph.nodes
- List of nodes for this graph.graphStatistics
- Information for this graph.
-
-
Method Details
-
getGraphInformation
- Returns:
- The GraphStatistics instance associated with this graph.
-
get
Fetch the node with the given ID. Complexity: O(1).- Parameters:
id
- ID of the node to fetch.- Returns:
- Node with the given ID.
-
size
public int size()- Returns:
- Number of nodes in this graph.
-
getNodes
- Returns:
- List of nodes in this graph (unmodifiable).
- See Also:
Collections.unmodifiableList(List)
-
getMapId
public java.lang.String getMapId()- Returns:
- ID of the map associated with this graph.
-
getMapName
public java.lang.String getMapName()- Returns:
- Name of the map associated with this graph.
-
transpose
- Returns:
- Transpose graph of this graph.
-
toString
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-