@Override @CanIgnoreReturnValue public boolean removeNode(N node) { checkNotNull(node, "node"); NetworkConnections<N, E> connections = nodeConnections.get(node); if (connections == null) { return false; } // Since views are returned, we need to copy the edges that will be removed. // Thus we avoid modifying the underlying view while iterating over it. for (E edge : ImmutableList.copyOf(connections.incidentEdges())) { removeEdge(edge); } nodeConnections.remove(node); return true; }
@Override @CanIgnoreReturnValue public boolean removeNode(N node) { checkNotNull(node, "node"); NetworkConnections<N, E> connections = nodeConnections.get(node); if (connections == null) { return false; } // Since views are returned, we need to copy the edges that will be removed. // Thus we avoid modifying the underlying view while iterating over it. for (E edge : ImmutableList.copyOf(connections.incidentEdges())) { removeEdge(edge); } nodeConnections.remove(node); return true; }
@Override @CanIgnoreReturnValue public boolean removeEdge(E edge) { checkNotNull(edge, "edge"); N nodeU = edgeToReferenceNode.get(edge); if (nodeU == null) { return false; } NetworkConnections<N, E> connectionsU = nodeConnections.get(nodeU); N nodeV = connectionsU.adjacentNode(edge); NetworkConnections<N, E> connectionsV = nodeConnections.get(nodeV); connectionsU.removeOutEdge(edge); connectionsV.removeInEdge(edge, allowsSelfLoops() && nodeU.equals(nodeV)); edgeToReferenceNode.remove(edge); return true; }
@Override @CanIgnoreReturnValue public boolean removeNode(N node) { checkNotNull(node, "node"); NetworkConnections<N, E> connections = nodeConnections.get(node); if (connections == null) { return false; } // Since views are returned, we need to copy the edges that will be removed. // Thus we avoid modifying the underlying view while iterating over it. for (E edge : ImmutableList.copyOf(connections.incidentEdges())) { removeEdge(edge); } nodeConnections.remove(node); return true; }
@Test public void testRemoveEqualKeyWithDifferentReference() { String fooReference1 = new String("foo"); String fooReference2 = new String("foo"); assertThat(fooReference1).isNotSameAs(fooReference2); assertThat(mapCache.put(fooReference1, "bar")).isNull(); assertThat(mapCache.get(fooReference1)).isEqualTo("bar"); // ensure first reference is cached assertThat(mapCache.remove(fooReference2)).isEqualTo("bar"); assertThat(mapCache.get(fooReference1)).isNull(); }
@Override @CanIgnoreReturnValue public boolean removeEdge(E edge) { checkNotNull(edge, "edge"); N nodeU = edgeToReferenceNode.get(edge); if (nodeU == null) { return false; } NetworkConnections<N, E> connectionsU = nodeConnections.get(nodeU); N nodeV = connectionsU.adjacentNode(edge); NetworkConnections<N, E> connectionsV = nodeConnections.get(nodeV); connectionsU.removeOutEdge(edge); connectionsV.removeInEdge(edge, allowsSelfLoops() && nodeU.equals(nodeV)); edgeToReferenceNode.remove(edge); return true; }
@Override @CanIgnoreReturnValue public boolean removeEdge(E edge) { checkNotNull(edge, "edge"); N nodeU = edgeToReferenceNode.get(edge); if (nodeU == null) { return false; } NetworkConnections<N, E> connectionsU = nodeConnections.get(nodeU); N nodeV = connectionsU.adjacentNode(edge); NetworkConnections<N, E> connectionsV = nodeConnections.get(nodeV); connectionsU.removeOutEdge(edge); connectionsV.removeInEdge(edge, allowsSelfLoops() && nodeU.equals(nodeV)); edgeToReferenceNode.remove(edge); return true; }
@Override @CanIgnoreReturnValue public boolean removeNode(N node) { checkNotNull(node, "node"); GraphConnections<N, V> connections = nodeConnections.get(node); if (connections == null) { return false; } if (allowsSelfLoops()) { // Remove self-loop (if any) first, so we don't get CME while removing incident edges. if (connections.removeSuccessor(node) != null) { connections.removePredecessor(node); --edgeCount; } } for (N successor : connections.successors()) { nodeConnections.getWithoutCaching(successor).removePredecessor(node); --edgeCount; } if (isDirected()) { // In undirected graphs, the successor and predecessor sets are equal. for (N predecessor : connections.predecessors()) { checkState(nodeConnections.getWithoutCaching(predecessor).removeSuccessor(node) != null); --edgeCount; } } nodeConnections.remove(node); checkNonNegative(edgeCount); return true; }
@Override @CanIgnoreReturnValue public boolean removeNode(N node) { checkNotNull(node, "node"); GraphConnections<N, V> connections = nodeConnections.get(node); if (connections == null) { return false; } if (allowsSelfLoops()) { // Remove self-loop (if any) first, so we don't get CME while removing incident edges. if (connections.removeSuccessor(node) != null) { connections.removePredecessor(node); --edgeCount; } } for (N successor : connections.successors()) { nodeConnections.getWithoutCaching(successor).removePredecessor(node); --edgeCount; } if (isDirected()) { // In undirected graphs, the successor and predecessor sets are equal. for (N predecessor : connections.predecessors()) { checkState(nodeConnections.getWithoutCaching(predecessor).removeSuccessor(node) != null); --edgeCount; } } nodeConnections.remove(node); checkNonNegative(edgeCount); return true; }
@Override @CanIgnoreReturnValue public boolean removeNode(N node) { checkNotNull(node, "node"); GraphConnections<N, V> connections = nodeConnections.get(node); if (connections == null) { return false; } if (allowsSelfLoops()) { // Remove self-loop (if any) first, so we don't get CME while removing incident edges. if (connections.removeSuccessor(node) != null) { connections.removePredecessor(node); --edgeCount; } } for (N successor : connections.successors()) { nodeConnections.getWithoutCaching(successor).removePredecessor(node); --edgeCount; } if (isDirected()) { // In undirected graphs, the successor and predecessor sets are equal. for (N predecessor : connections.predecessors()) { checkState(nodeConnections.getWithoutCaching(predecessor).removeSuccessor(node) != null); --edgeCount; } } nodeConnections.remove(node); checkNonNegative(edgeCount); return true; }
@Override @CanIgnoreReturnValue public boolean removeNode(N node) { checkNotNull(node, "node"); NetworkConnections<N, E> connections = nodeConnections.get(node); if (connections == null) { return false; } // Since views are returned, we need to copy the edges that will be removed. // Thus we avoid modifying the underlying view while iterating over it. for (E edge : ImmutableList.copyOf(connections.incidentEdges())) { removeEdge(edge); } nodeConnections.remove(node); return true; }
@Override @CanIgnoreReturnValue public boolean removeNode(N node) { checkNotNull(node, "node"); NetworkConnections<N, E> connections = nodeConnections.get(node); if (connections == null) { return false; } // Since views are returned, we need to copy the edges that will be removed. // Thus we avoid modifying the underlying view while iterating over it. for (E edge : ImmutableList.copyOf(connections.incidentEdges())) { removeEdge(edge); } nodeConnections.remove(node); return true; }
@Override @CanIgnoreReturnValue public boolean removeEdge(E edge) { checkNotNull(edge, "edge"); N nodeU = edgeToReferenceNode.get(edge); if (nodeU == null) { return false; } NetworkConnections<N, E> connectionsU = nodeConnections.get(nodeU); N nodeV = connectionsU.adjacentNode(edge); NetworkConnections<N, E> connectionsV = nodeConnections.get(nodeV); connectionsU.removeOutEdge(edge); connectionsV.removeInEdge(edge, allowsSelfLoops() && nodeU.equals(nodeV)); edgeToReferenceNode.remove(edge); return true; }
@Override @CanIgnoreReturnValue public boolean removeEdge(E edge) { checkNotNull(edge, "edge"); N nodeU = edgeToReferenceNode.get(edge); if (nodeU == null) { return false; } NetworkConnections<N, E> connectionsU = nodeConnections.get(nodeU); N nodeV = connectionsU.adjacentNode(edge); NetworkConnections<N, E> connectionsV = nodeConnections.get(nodeV); connectionsU.removeOutEdge(edge); connectionsV.removeInEdge(edge, allowsSelfLoops() && nodeU.equals(nodeV)); edgeToReferenceNode.remove(edge); return true; }
@Test public void testRemoveEqualKeyWithDifferentReference() { String fooReference1 = new String("foo"); String fooReference2 = new String("foo"); assertThat(fooReference1).isNotSameAs(fooReference2); assertThat(mapCache.put(fooReference1, "bar")).isNull(); assertThat(mapCache.get(fooReference1)).isEqualTo("bar"); // ensure first reference is cached assertThat(mapCache.remove(fooReference2)).isEqualTo("bar"); assertThat(mapCache.get(fooReference1)).isNull(); }
@Override @CanIgnoreReturnValue public boolean removeNode(N node) { checkNotNull(node, "node"); GraphConnections<N, V> connections = nodeConnections.get(node); if (connections == null) { return false; } if (allowsSelfLoops()) { // Remove self-loop (if any) first, so we don't get CME while removing incident edges. if (connections.removeSuccessor(node) != null) { connections.removePredecessor(node); --edgeCount; } } for (N successor : connections.successors()) { nodeConnections.getWithoutCaching(successor).removePredecessor(node); --edgeCount; } if (isDirected()) { // In undirected graphs, the successor and predecessor sets are equal. for (N predecessor : connections.predecessors()) { checkState(nodeConnections.getWithoutCaching(predecessor).removeSuccessor(node) != null); --edgeCount; } } nodeConnections.remove(node); checkNonNegative(edgeCount); return true; }
@Override @CanIgnoreReturnValue public boolean removeNode(N node) { checkNotNull(node, "node"); GraphConnections<N, V> connections = nodeConnections.get(node); if (connections == null) { return false; } if (allowsSelfLoops()) { // Remove self-loop (if any) first, so we don't get CME while removing incident edges. if (connections.removeSuccessor(node) != null) { connections.removePredecessor(node); --edgeCount; } } for (N successor : connections.successors()) { nodeConnections.getWithoutCaching(successor).removePredecessor(node); --edgeCount; } if (isDirected()) { // In undirected graphs, the successor and predecessor sets are equal. for (N predecessor : connections.predecessors()) { checkState(nodeConnections.getWithoutCaching(predecessor).removeSuccessor(node) != null); --edgeCount; } } nodeConnections.remove(node); checkNonNegative(edgeCount); return true; }