@Test public void copyOf_nullArgument() { try { copyOf((Graph<?>) null); fail("Should have rejected a null graph."); } catch (NullPointerException expected) { } }
@Test public void copyOf_undirectedNetwork() { Network<Integer, String> undirectedGraph = buildUndirectedNetwork(); Network<Integer, String> copy = copyOf(undirectedGraph); assertThat(copy).isEqualTo(undirectedGraph); }
@Test public void copyOf_directedGraph() { Graph<Integer> directedGraph = buildDirectedGraph(); Graph<Integer> copy = copyOf(directedGraph); assertThat(copy).isEqualTo(directedGraph); }
@Test public void copyOf_undirectedGraph() { Graph<Integer> undirectedGraph = buildUndirectedGraph(); Graph<Integer> copy = copyOf(undirectedGraph); assertThat(copy).isEqualTo(undirectedGraph); }
@Test public void copyOf_directedValueGraph() { ValueGraph<Integer, String> directedGraph = buildDirectedValueGraph(); ValueGraph<Integer, String> copy = copyOf(directedGraph); assertThat(copy).isEqualTo(directedGraph); }
@Test public void copyOf_undirectedValueGraph() { ValueGraph<Integer, String> undirectedGraph = buildUndirectedValueGraph(); ValueGraph<Integer, String> copy = copyOf(undirectedGraph); assertThat(copy).isEqualTo(undirectedGraph); }
@Test public void copyOf_directedNetwork() { Network<Integer, String> directedGraph = buildDirectedNetwork(); Network<Integer, String> copy = copyOf(directedGraph); assertThat(copy).isEqualTo(directedGraph); }
MutableGraph<T> graphCopy = Graphs.copyOf(graph); List<T> l = new ArrayList<>(); Set<T> s = graphCopy.nodes().stream()
@After public void validateGraphState() { assertStronglyEquivalent(graph, Graphs.copyOf(graph)); assertStronglyEquivalent(graph, ImmutableValueGraph.copyOf(graph)); Graph<Integer> asGraph = graph.asGraph(); AbstractGraphTest.validateGraph(asGraph); assertThat(graph.nodes()).isEqualTo(asGraph.nodes()); assertThat(graph.edges()).isEqualTo(asGraph.edges()); assertThat(graph.nodeOrder()).isEqualTo(asGraph.nodeOrder()); assertThat(graph.isDirected()).isEqualTo(asGraph.isDirected()); assertThat(graph.allowsSelfLoops()).isEqualTo(asGraph.allowsSelfLoops()); for (Integer node : graph.nodes()) { assertThat(graph.adjacentNodes(node)).isEqualTo(asGraph.adjacentNodes(node)); assertThat(graph.predecessors(node)).isEqualTo(asGraph.predecessors(node)); assertThat(graph.successors(node)).isEqualTo(asGraph.successors(node)); assertThat(graph.degree(node)).isEqualTo(asGraph.degree(node)); assertThat(graph.inDegree(node)).isEqualTo(asGraph.inDegree(node)); assertThat(graph.outDegree(node)).isEqualTo(asGraph.outDegree(node)); for (Integer otherNode : graph.nodes()) { boolean hasEdge = graph.hasEdgeConnecting(node, otherNode); assertThat(hasEdge).isEqualTo(asGraph.hasEdgeConnecting(node, otherNode)); assertThat(graph.edgeValueOrDefault(node, otherNode, null) != null).isEqualTo(hasEdge); assertThat(!graph.edgeValueOrDefault(node, otherNode, DEFAULT).equals(DEFAULT)) .isEqualTo(hasEdge); } } }
static <N> void validateGraph(Graph<N> graph) { assertStronglyEquivalent(graph, Graphs.copyOf(graph)); assertStronglyEquivalent(graph, ImmutableGraph.copyOf(graph));
static <N, E> void validateNetwork(Network<N, E> network) { assertStronglyEquivalent(network, Graphs.copyOf(network)); assertStronglyEquivalent(network, ImmutableNetwork.copyOf(network));
/** * Returns a shallow copy of this graph instance. Neither edges nor vertices are cloned. * * @return a shallow copy of this graph. * * @throws RuntimeException in case the clone is not supported * * @see java.lang.Object#clone() */ @Override public Object clone() { try { MutableGraphAdapter<V> newGraph = TypeUtil.uncheckedCast(super.clone()); newGraph.unmodifiableVertexSet = null; newGraph.unmodifiableEdgeSet = null; newGraph.graph = Graphs.copyOf(this.graph); return newGraph; } catch (CloneNotSupportedException e) { e.printStackTrace(); throw new RuntimeException(); } }
/** * Returns a shallow copy of this graph instance. Neither edges nor vertices are cloned. * * @return a shallow copy of this graph. * * @throws RuntimeException in case the clone is not supported * * @see java.lang.Object#clone() */ @Override public Object clone() { try { ImmutableGraphAdapter<V> newGraph = TypeUtil.uncheckedCast(super.clone()); newGraph.unmodifiableVertexSet = null; newGraph.unmodifiableEdgeSet = null; newGraph.graph = ImmutableGraph.copyOf(Graphs.copyOf(this.graph)); return newGraph; } catch (CloneNotSupportedException e) { e.printStackTrace(); throw new RuntimeException(); } }
@Test public void copyOf_nullArgument() { try { copyOf((Graph<?>) null); fail("Should have rejected a null graph."); } catch (NullPointerException expected) { } }
@Test public void copyOf_directedValueGraph() { ValueGraph<Integer, String> directedGraph = buildDirectedValueGraph(); ValueGraph<Integer, String> copy = copyOf(directedGraph); assertThat(copy).isEqualTo(directedGraph); }
@Test public void copyOf_undirectedValueGraph() { ValueGraph<Integer, String> undirectedGraph = buildUndirectedValueGraph(); ValueGraph<Integer, String> copy = copyOf(undirectedGraph); assertThat(copy).isEqualTo(undirectedGraph); }
@Test public void copyOf_undirectedGraph() { Graph<Integer> undirectedGraph = buildUndirectedGraph(); Graph<Integer> copy = copyOf(undirectedGraph); assertThat(copy).isEqualTo(undirectedGraph); }
@Test public void copyOf_directedGraph() { Graph<Integer> directedGraph = buildDirectedGraph(); Graph<Integer> copy = copyOf(directedGraph); assertThat(copy).isEqualTo(directedGraph); }
@Test public void copyOf_directedNetwork() { Network<Integer, String> directedGraph = buildDirectedNetwork(); Network<Integer, String> copy = copyOf(directedGraph); assertThat(copy).isEqualTo(directedGraph); }
@Test public void copyOf_undirectedNetwork() { Network<Integer, String> undirectedGraph = buildUndirectedNetwork(); Network<Integer, String> copy = copyOf(undirectedGraph); assertThat(copy).isEqualTo(undirectedGraph); }