diff --git a/android/guava-tests/test/com/google/common/graph/AbstractGraphTest.java b/android/guava-tests/test/com/google/common/graph/AbstractGraphTest.java index a8209244c037..756a50c68276 100644 --- a/android/guava-tests/test/com/google/common/graph/AbstractGraphTest.java +++ b/android/guava-tests/test/com/google/common/graph/AbstractGraphTest.java @@ -385,13 +385,10 @@ public void removeNode_nodeNotPresent() { public void removeNode_queryAfterRemoval() { assume().that(graphIsMutable()).isTrue(); - putEdge(N1, N2); - putEdge(N2, N1); - Set n1AdjacentNodes = graph.adjacentNodes(N1); - Set n2AdjacentNodes = graph.adjacentNodes(N2); + addNode(N1); + @SuppressWarnings("unused") + Set unused = graph.adjacentNodes(N1); // ensure cache (if any) is populated assertThat(graphAsMutableGraph.removeNode(N1)).isTrue(); - assertThat(n1AdjacentNodes).isEmpty(); - assertThat(n2AdjacentNodes).isEmpty(); IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> graph.adjacentNodes(N1)); assertNodeNotInGraphErrorMessage(e); diff --git a/android/guava-tests/test/com/google/common/graph/AbstractNetworkTest.java b/android/guava-tests/test/com/google/common/graph/AbstractNetworkTest.java index b9558f706e86..a5fc1b254bc6 100644 --- a/android/guava-tests/test/com/google/common/graph/AbstractNetworkTest.java +++ b/android/guava-tests/test/com/google/common/graph/AbstractNetworkTest.java @@ -670,12 +670,11 @@ public void removeNode_nodeNotPresent() { public void removeNode_queryAfterRemoval() { assume().that(graphIsMutable()).isTrue(); - addEdge(N1, N2, E12); - Set n1AdjacentNodes = networkAsMutableNetwork.adjacentNodes(N1); - Set n2AdjacentNodes = networkAsMutableNetwork.adjacentNodes(N2); + addNode(N1); + @SuppressWarnings("unused") + Set unused = + networkAsMutableNetwork.adjacentNodes(N1); // ensure cache (if any) is populated assertTrue(networkAsMutableNetwork.removeNode(N1)); - assertThat(n1AdjacentNodes).isEmpty(); - assertThat(n2AdjacentNodes).isEmpty(); IllegalArgumentException e = assertThrows( IllegalArgumentException.class, () -> networkAsMutableNetwork.adjacentNodes(N1)); diff --git a/android/guava/src/com/google/common/graph/StandardMutableValueGraph.java b/android/guava/src/com/google/common/graph/StandardMutableValueGraph.java index 1ad474083610..0ea641a5b1cd 100644 --- a/android/guava/src/com/google/common/graph/StandardMutableValueGraph.java +++ b/android/guava/src/com/google/common/graph/StandardMutableValueGraph.java @@ -24,7 +24,6 @@ import static com.google.common.graph.Graphs.checkPositive; import static java.util.Objects.requireNonNull; -import com.google.common.collect.ImmutableList; import com.google.errorprone.annotations.CanIgnoreReturnValue; import javax.annotation.CheckForNull; @@ -137,21 +136,17 @@ public boolean removeNode(N node) { } } - for (N successor : ImmutableList.copyOf(connections.successors())) { + for (N successor : connections.successors()) { // requireNonNull is safe because the node is a successor. requireNonNull(nodeConnections.getWithoutCaching(successor)).removePredecessor(node); - requireNonNull(connections.removeSuccessor(successor)); --edgeCount; } if (isDirected()) { // In undirected graphs, the successor and predecessor sets are equal. - // Since views are returned, we need to copy the predecessors that will be removed. - // Thus we avoid modifying the underlying view while iterating over it. - for (N predecessor : ImmutableList.copyOf(connections.predecessors())) { + for (N predecessor : connections.predecessors()) { // requireNonNull is safe because the node is a predecessor. checkState( requireNonNull(nodeConnections.getWithoutCaching(predecessor)).removeSuccessor(node) != null); - connections.removePredecessor(predecessor); --edgeCount; } } diff --git a/guava-tests/test/com/google/common/graph/AbstractGraphTest.java b/guava-tests/test/com/google/common/graph/AbstractGraphTest.java index a8209244c037..756a50c68276 100644 --- a/guava-tests/test/com/google/common/graph/AbstractGraphTest.java +++ b/guava-tests/test/com/google/common/graph/AbstractGraphTest.java @@ -385,13 +385,10 @@ public void removeNode_nodeNotPresent() { public void removeNode_queryAfterRemoval() { assume().that(graphIsMutable()).isTrue(); - putEdge(N1, N2); - putEdge(N2, N1); - Set n1AdjacentNodes = graph.adjacentNodes(N1); - Set n2AdjacentNodes = graph.adjacentNodes(N2); + addNode(N1); + @SuppressWarnings("unused") + Set unused = graph.adjacentNodes(N1); // ensure cache (if any) is populated assertThat(graphAsMutableGraph.removeNode(N1)).isTrue(); - assertThat(n1AdjacentNodes).isEmpty(); - assertThat(n2AdjacentNodes).isEmpty(); IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> graph.adjacentNodes(N1)); assertNodeNotInGraphErrorMessage(e); diff --git a/guava-tests/test/com/google/common/graph/AbstractNetworkTest.java b/guava-tests/test/com/google/common/graph/AbstractNetworkTest.java index a29ffc5ae42b..5d3f53505870 100644 --- a/guava-tests/test/com/google/common/graph/AbstractNetworkTest.java +++ b/guava-tests/test/com/google/common/graph/AbstractNetworkTest.java @@ -677,12 +677,11 @@ public void removeNode_nodeNotPresent() { public void removeNode_queryAfterRemoval() { assume().that(graphIsMutable()).isTrue(); - addEdge(N1, N2, E12); - Set n1AdjacentNodes = networkAsMutableNetwork.adjacentNodes(N1); - Set n2AdjacentNodes = networkAsMutableNetwork.adjacentNodes(N2); + addNode(N1); + @SuppressWarnings("unused") + Set unused = + networkAsMutableNetwork.adjacentNodes(N1); // ensure cache (if any) is populated assertTrue(networkAsMutableNetwork.removeNode(N1)); - assertThat(n1AdjacentNodes).isEmpty(); - assertThat(n2AdjacentNodes).isEmpty(); IllegalArgumentException e = assertThrows( IllegalArgumentException.class, () -> networkAsMutableNetwork.adjacentNodes(N1)); diff --git a/guava/src/com/google/common/graph/StandardMutableValueGraph.java b/guava/src/com/google/common/graph/StandardMutableValueGraph.java index 1ad474083610..0ea641a5b1cd 100644 --- a/guava/src/com/google/common/graph/StandardMutableValueGraph.java +++ b/guava/src/com/google/common/graph/StandardMutableValueGraph.java @@ -24,7 +24,6 @@ import static com.google.common.graph.Graphs.checkPositive; import static java.util.Objects.requireNonNull; -import com.google.common.collect.ImmutableList; import com.google.errorprone.annotations.CanIgnoreReturnValue; import javax.annotation.CheckForNull; @@ -137,21 +136,17 @@ public boolean removeNode(N node) { } } - for (N successor : ImmutableList.copyOf(connections.successors())) { + for (N successor : connections.successors()) { // requireNonNull is safe because the node is a successor. requireNonNull(nodeConnections.getWithoutCaching(successor)).removePredecessor(node); - requireNonNull(connections.removeSuccessor(successor)); --edgeCount; } if (isDirected()) { // In undirected graphs, the successor and predecessor sets are equal. - // Since views are returned, we need to copy the predecessors that will be removed. - // Thus we avoid modifying the underlying view while iterating over it. - for (N predecessor : ImmutableList.copyOf(connections.predecessors())) { + for (N predecessor : connections.predecessors()) { // requireNonNull is safe because the node is a predecessor. checkState( requireNonNull(nodeConnections.getWithoutCaching(predecessor)).removeSuccessor(node) != null); - connections.removePredecessor(predecessor); --edgeCount; } }