Returns the node at the other end of edge from node. @throws UnsupportedOperationException if graph is a Hypergraph @throws IllegalArgumentException if edge is not incident to node
(Network<N, ?> graph, Object edge, Object node)
| 58 | |
| 59 | |
| 60 | public static <N> N oppositeNode(Network<N, ?> graph, Object edge, Object node) { |
| 61 | if (graph instanceof Hypergraph) { |
| 62 | throw new UnsupportedOperationException(); |
| 63 | } |
| 64 | checkNotNull(node, "node"); |
| 65 | Iterator<N> incidentNodesIterator = graph.incidentNodes(edge).iterator(); |
| 66 | N node1 = incidentNodesIterator.next(); |
| 67 | N node2 = incidentNodesIterator.hasNext() ? incidentNodesIterator.next() : node1; |
| 68 | if (node.equals(node1)) { |
| 69 | return node2; |
| 70 | } else { |
| 71 | checkArgument(node.equals(node2), "Edge %s is not incident to node %s", edge, node); |
| 72 | return node1; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Returns an unmodifiable view of edges that are parallel to {@code edge}, i.e. the set of edges |
no test coverage detected