Adds edge to graph with the specified incident nodes, in the order returned by nodes' iterator.
(MutableNetwork<N, E> graph, E edge, Iterable<N> nodes)
| 102 | */ |
| 103 | |
| 104 | @CanIgnoreReturnValue |
| 105 | public static <N, E> boolean addEdge(MutableNetwork<N, E> graph, E edge, Iterable<N> nodes) { |
| 106 | checkNotNull(graph, "graph"); |
| 107 | checkNotNull(edge, "edge"); |
| 108 | checkNotNull(nodes, "nodes"); |
| 109 | if (graph instanceof Hypergraph) { |
| 110 | return ((Hypergraph<N, E>) graph).addEdge(edge, nodes); |
| 111 | } |
| 112 | Iterator<N> nodesIterator = nodes.iterator(); |
| 113 | checkArgument( |
| 114 | nodesIterator.hasNext(), |
| 115 | "'graph' is not a Hypergraph, and 'nodes' has < 1 elements: %s", |
| 116 | nodes); |
| 117 | N node1 = nodesIterator.next(); |
| 118 | N node2 = nodesIterator.hasNext() ? nodesIterator.next() : node1; |
| 119 | checkArgument( |
| 120 | !nodesIterator.hasNext(), |
| 121 | "'graph' is not a Hypergraph, and 'nodes' has > 2 elements: %s", |
| 122 | nodes); |
| 123 | return graph.addEdge(edge, node1, node2); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Creates a mutable copy of {@code graph}, using the same nodes. |
no test coverage detected