@Test public void builder_expectedEdgeCount_negative() { try { NetworkBuilder.directed().expectedEdgeCount(-1); fail("Should have rejected negative expected edge count."); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).contains(ERROR_NEGATIVE_COUNT); } }
/** Creates a mutable copy of {@code network} with the same nodes and edges. */ public static <N, E> MutableNetwork<N, E> copyOf(Network<N, E> network) { MutableNetwork<N, E> copy = NetworkBuilder.from(network) .expectedNodeCount(network.nodes().size()) .expectedEdgeCount(network.edges().size()) .build(); for (N node : network.nodes()) { copy.addNode(node); } for (E edge : network.edges()) { EndpointPair<N> endpointPair = network.incidentNodes(edge); copy.addEdge(endpointPair.nodeU(), endpointPair.nodeV(), edge); } return copy; }
@Test public void createUndirected_expectedEdgeCount() { MutableNetwork<Integer, String> undirectedGraph = NetworkBuilder.undirected().expectedEdgeCount(EDGE_COUNT).build(); assertThat(undirectedGraph.addEdge(N1, N2, E12)).isTrue(); assertThat(undirectedGraph.edgesConnecting(N1, N2)).isEqualTo(ImmutableSet.of(E12)); assertThat(undirectedGraph.edgesConnecting(N2, N1)).isEqualTo(ImmutableSet.of(E12)); }
@Test public void createDirected_expectedEdgeCount() { MutableNetwork<Integer, String> directedGraph = NetworkBuilder.directed().expectedEdgeCount(EDGE_COUNT).build(); assertThat(directedGraph.addEdge(N1, N2, E12)).isTrue(); assertThat(directedGraph.edgesConnecting(N1, N2)).isEqualTo(ImmutableSet.of(E12)); assertThat(directedGraph.edgesConnecting(N2, N1)).isEmpty(); }
/** Creates a mutable copy of {@code network} with the same nodes and edges. */ public static <N, E> MutableNetwork<N, E> copyOf(Network<N, E> network) { MutableNetwork<N, E> copy = NetworkBuilder.from(network) .expectedNodeCount(network.nodes().size()) .expectedEdgeCount(network.edges().size()) .build(); for (N node : network.nodes()) { copy.addNode(node); } for (E edge : network.edges()) { EndpointPair<N> endpointPair = network.incidentNodes(edge); copy.addEdge(endpointPair.nodeU(), endpointPair.nodeV(), edge); } return copy; }
/** Creates a mutable copy of {@code network} with the same nodes and edges. */ public static <N, E> MutableNetwork<N, E> copyOf(Network<N, E> network) { MutableNetwork<N, E> copy = NetworkBuilder.from(network) .expectedNodeCount(network.nodes().size()) .expectedEdgeCount(network.edges().size()) .build(); for (N node : network.nodes()) { copy.addNode(node); } for (E edge : network.edges()) { EndpointPair<N> endpointPair = network.incidentNodes(edge); copy.addEdge(endpointPair.nodeU(), endpointPair.nodeV(), edge); } return copy; }
directed ? NetworkBuilder.directed() : NetworkBuilder.undirected(); MutableNetwork<N, E> graph = builder.expectedNodeCount(node_count).expectedEdgeCount(edge_count).build();
@Test public void builder_expectedEdgeCount_negative() { try { NetworkBuilder.directed().expectedEdgeCount(-1); fail("Should have rejected negative expected edge count."); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).contains(ERROR_NEGATIVE_COUNT); } }
/** Returns the subgraph containing only {@link DependencyEdge}s that would not break a cycle. */ // TODO(dpb): Return a network containing only Binding nodes. private ImmutableNetwork<Node, DependencyEdge> nonCycleBreakingDependencyGraph( BindingGraph bindingGraph) { MutableNetwork<Node, DependencyEdge> dependencyNetwork = NetworkBuilder.from(bindingGraph.network()) .expectedNodeCount(bindingGraph.network().nodes().size()) .expectedEdgeCount(bindingGraph.dependencyEdges().size()) .build(); bindingGraph.dependencyEdges().stream() .filter(edge -> !breaksCycle(edge, bindingGraph)) .forEach( edge -> { EndpointPair<Node> endpoints = bindingGraph.network().incidentNodes(edge); dependencyNetwork.addEdge(endpoints.source(), endpoints.target(), edge); }); return ImmutableNetwork.copyOf(dependencyNetwork); }
/** Creates a mutable copy of {@code network} with the same nodes and edges. */ public static <N, E> MutableNetwork<N, E> copyOf(Network<N, E> network) { MutableNetwork<N, E> copy = NetworkBuilder.from(network) .expectedNodeCount(network.nodes().size()) .expectedEdgeCount(network.edges().size()) .build(); for (N node : network.nodes()) { copy.addNode(node); } for (E edge : network.edges()) { EndpointPair<N> endpointPair = network.incidentNodes(edge); copy.addEdge(endpointPair.nodeU(), endpointPair.nodeV(), edge); } return copy; }
/** Creates a mutable copy of {@code network} with the same nodes and edges. */ public static <N, E> MutableNetwork<N, E> copyOf(Network<N, E> network) { MutableNetwork<N, E> copy = NetworkBuilder.from(network) .expectedNodeCount(network.nodes().size()) .expectedEdgeCount(network.edges().size()) .build(); for (N node : network.nodes()) { copy.addNode(node); } for (E edge : network.edges()) { EndpointPair<N> endpointPair = network.incidentNodes(edge); copy.addEdge(endpointPair.nodeU(), endpointPair.nodeV(), edge); } return copy; }
@Test public void createUndirected_expectedEdgeCount() { MutableNetwork<Integer, String> undirectedGraph = NetworkBuilder.undirected().expectedEdgeCount(EDGE_COUNT).build(); assertThat(undirectedGraph.addEdge(N1, N2, E12)).isTrue(); assertThat(undirectedGraph.edgesConnecting(N1, N2)).isEqualTo(ImmutableSet.of(E12)); assertThat(undirectedGraph.edgesConnecting(N2, N1)).isEqualTo(ImmutableSet.of(E12)); }
@Test public void createDirected_expectedEdgeCount() { MutableNetwork<Integer, String> directedGraph = NetworkBuilder.directed().expectedEdgeCount(EDGE_COUNT).build(); assertThat(directedGraph.addEdge(N1, N2, E12)).isTrue(); assertThat(directedGraph.edgesConnecting(N1, N2)).isEqualTo(ImmutableSet.of(E12)); assertThat(directedGraph.edgesConnecting(N2, N1)).isEmpty(); }