add Edge
Adds an edge between two nodes in the graph, and creates the nodes if they don't exist.
If the graph is unweighted, the edge is added without a weight. If a weight is provided for an unweighted graph, an error is thrown. If the graph is weighted, a weight must be provided; otherwise, an error is thrown.
Parameters
node1
The starting node of the edge.
node2
The ending node of the edge.
weight
The weight of the edge (required for weighted graphs). Defaults to null.
Throws
Illegal State Exception
If a weight is provided for an unweighted graph or if no weight is provided for a weighted graph.