/** Returns an empty {@link MutableNetwork} with the properties of this {@link NetworkBuilder}. */ public <N1 extends N, E1 extends E> MutableNetwork<N1, E1> build() { return new ConfigurableMutableNetwork<>(this); }
checkNotNull(edge, "edge"); if (containsEdge(edge)) { EndpointPair<N> existingIncidentNodes = incidentNodes(edge); EndpointPair<N> newIncidentNodes = EndpointPair.of(this, nodeU, nodeV); checkArgument( if (!allowsParallelEdges()) { checkArgument( !(connectionsU != null && connectionsU.successors().contains(nodeV)), if (!allowsSelfLoops()) { checkArgument(!isSelfLoop, SELF_LOOPS_NOT_ALLOWED, nodeU); connectionsU = addNodeInternal(nodeU); connectionsV = addNodeInternal(nodeV);
@Override @CanIgnoreReturnValue public boolean addNode(N node) { checkNotNull(node, "node"); if (containsNode(node)) { return false; } addNodeInternal(node); return true; }
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(); } }
/** * Adds {@code node} to the graph and returns the associated {@link NetworkConnections}. * * @throws IllegalStateException if {@code node} is already present */ @CanIgnoreReturnValue private NetworkConnections<N, E> addNodeInternal(N node) { NetworkConnections<N, E> connections = newConnections(); checkState(nodeConnections.put(node, connections) == null); return connections; }
@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; }
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(); } }
/** * Adds {@code node} to the graph and returns the associated {@link NetworkConnections}. * * @throws IllegalStateException if {@code node} is already present */ @CanIgnoreReturnValue private NetworkConnections<N, E> addNodeInternal(N node) { NetworkConnections<N, E> connections = newConnections(); checkState(nodeConnections.put(node, connections) == null); return connections; }
@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; }
checkNotNull(edge, "edge"); if (containsEdge(edge)) { EndpointPair<N> existingIncidentNodes = incidentNodes(edge); EndpointPair<N> newIncidentNodes = EndpointPair.of(this, nodeU, nodeV); checkArgument( if (!allowsParallelEdges()) { checkArgument( !(connectionsU != null && connectionsU.successors().contains(nodeV)), if (!allowsSelfLoops()) { checkArgument(!isSelfLoop, SELF_LOOPS_NOT_ALLOWED, nodeU); connectionsU = addNodeInternal(nodeU); connectionsV = addNodeInternal(nodeV);
@Override @CanIgnoreReturnValue public boolean addNode(N node) { checkNotNull(node, "node"); if (containsNode(node)) { return false; } addNodeInternal(node); return true; }
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(); } }
/** * Adds {@code node} to the graph and returns the associated {@link NetworkConnections}. * * @throws IllegalStateException if {@code node} is already present */ @CanIgnoreReturnValue private NetworkConnections<N, E> addNodeInternal(N node) { NetworkConnections<N, E> connections = newConnections(); checkState(nodeConnections.put(node, connections) == null); return connections; }
@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; }
/** Returns an empty {@link MutableNetwork} with the properties of this {@link NetworkBuilder}. */ public <N1 extends N, E1 extends E> MutableNetwork<N1, E1> build() { return new ConfigurableMutableNetwork<>(this); }
checkNotNull(edge, "edge"); if (containsEdge(edge)) { EndpointPair<N> existingIncidentNodes = incidentNodes(edge); EndpointPair<N> newIncidentNodes = EndpointPair.of(this, nodeU, nodeV); checkArgument( if (!allowsParallelEdges()) { checkArgument( !(connectionsU != null && connectionsU.successors().contains(nodeV)), if (!allowsSelfLoops()) { checkArgument(!isSelfLoop, SELF_LOOPS_NOT_ALLOWED, nodeU); connectionsU = addNodeInternal(nodeU); connectionsV = addNodeInternal(nodeV);
@Override @CanIgnoreReturnValue public boolean addNode(N node) { checkNotNull(node, "node"); if (containsNode(node)) { return false; } addNodeInternal(node); return true; }