private NetworkConnections<N, E> newConnections() { return isDirected() ? allowsParallelEdges() ? DirectedMultiNetworkConnections.<N, E>of() : DirectedNetworkConnections.<N, E>of() : allowsParallelEdges() ? UndirectedMultiNetworkConnections.<N, E>of() : UndirectedNetworkConnections.<N, E>of(); } }
@Override public EndpointPair<N> incidentNodes(E edge) { N nodeU = checkedReferenceNode(edge); N nodeV = nodeConnections.get(nodeU).adjacentNode(edge); return EndpointPair.of(this, nodeU, nodeV); }
private GraphConnections<N, V> newConnections() { return isDirected() ? DirectedGraphConnections.<N, V>of() : UndirectedGraphConnections.<N, V>of(); } }
/** * Returns a {@link GraphBuilder} initialized with all properties queryable from {@code graph}. * * <p>The "queryable" properties are those that are exposed through the {@link Graph} interface, * such as {@link Graph#isDirected()}. Other properties, such as {@link #expectedNodeCount(int)}, * are not set in the new builder. */ public static <N> GraphBuilder<N> from(Graph<N> graph) { return new GraphBuilder<N>(graph.isDirected()) .allowsSelfLoops(graph.allowsSelfLoops()) .nodeOrder(graph.nodeOrder()); }
@Override public EndpointPair<N> incidentNodes(E edge) { EndpointPair<N> endpointPair = delegate().incidentNodes(edge); return EndpointPair.of(network, endpointPair.nodeV(), endpointPair.nodeU()); // transpose }
private static MutableGraph<Integer> buildUndirectedGraph() { MutableGraph<Integer> undirectedGraph = GraphBuilder.undirected().allowsSelfLoops(true).build(); undirectedGraph.putEdge(N1, N1); undirectedGraph.putEdge(N1, N2); undirectedGraph.putEdge(N2, N1); return undirectedGraph; }
@Override public V apply(EndpointPair<N> edge) { return graph.edgeValueOrDefault(edge.nodeU(), edge.nodeV(), null); } };
@Override public Set<E> edgesConnecting(EndpointPair<N> endpoints) { validateEndpoints(endpoints); return edgesConnecting(endpoints.nodeU(), endpoints.nodeV()); }
private static MutableValueGraph<Integer, String> buildUndirectedValueGraph() { MutableValueGraph<Integer, String> undirectedGraph = ValueGraphBuilder.undirected().allowsSelfLoops(true).build(); undirectedGraph.putEdgeValue(N1, N1, E11); undirectedGraph.putEdgeValue(N1, N2, E12); undirectedGraph.putEdgeValue(N2, N1, E21); // overwrites E12 return undirectedGraph; }
@Override public boolean putEdge(EndpointPair<N> endpoints) { validateEndpoints(endpoints); return putEdge(endpoints.nodeU(), endpoints.nodeV()); }
@Override public N apply(E edge) { return network.incidentNodes(edge).target(); } };
@Override public N apply(E edge) { return network.incidentNodes(edge).adjacentNode(node); } };
@Override public boolean hasEdgeConnecting(EndpointPair<N> endpoints) { return delegate().hasEdgeConnecting(transpose(endpoints)); } }
@Override public boolean hasEdgeConnecting(EndpointPair<N> endpoints) { return delegate().hasEdgeConnecting(transpose(endpoints)); } }