mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-27 17:42:33 -06:00
510 lines
23 KiB
Java
510 lines
23 KiB
Java
package com.google.common.graph;
|
|
|
|
import com.google.common.base.Function;
|
|
import com.google.common.base.Objects;
|
|
import com.google.common.base.Preconditions;
|
|
import com.google.common.collect.ImmutableSet;
|
|
import com.google.common.collect.Iterables;
|
|
import com.google.common.collect.Iterators;
|
|
import com.google.common.collect.Maps;
|
|
import java.util.Collection;
|
|
import java.util.HashMap;
|
|
import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import javax.annotation.CheckForNull;
|
|
|
|
@ElementTypesAreNonnullByDefault
|
|
/* loaded from: classes3.dex */
|
|
public final class Graphs {
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
/* loaded from: classes3.dex */
|
|
public enum NodeVisitState {
|
|
PENDING,
|
|
COMPLETE
|
|
}
|
|
|
|
private Graphs() {
|
|
}
|
|
|
|
public static <N> boolean hasCycle(Graph<N> graph) {
|
|
int size = graph.edges().size();
|
|
if (size == 0) {
|
|
return false;
|
|
}
|
|
if (!graph.isDirected() && size >= graph.nodes().size()) {
|
|
return true;
|
|
}
|
|
HashMap newHashMapWithExpectedSize = Maps.newHashMapWithExpectedSize(graph.nodes().size());
|
|
Iterator<N> it = graph.nodes().iterator();
|
|
while (it.hasNext()) {
|
|
if (subgraphHasCycle(graph, newHashMapWithExpectedSize, it.next(), null)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static boolean hasCycle(Network<?, ?> network) {
|
|
if (network.isDirected() || !network.allowsParallelEdges() || network.edges().size() <= network.asGraph().edges().size()) {
|
|
return hasCycle(network.asGraph());
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private static <N> boolean subgraphHasCycle(Graph<N> graph, Map<Object, NodeVisitState> map, N n, @CheckForNull N n2) {
|
|
NodeVisitState nodeVisitState = map.get(n);
|
|
if (nodeVisitState == NodeVisitState.COMPLETE) {
|
|
return false;
|
|
}
|
|
if (nodeVisitState == NodeVisitState.PENDING) {
|
|
return true;
|
|
}
|
|
map.put(n, NodeVisitState.PENDING);
|
|
for (N n3 : graph.successors((Graph<N>) n)) {
|
|
if (canTraverseWithoutReusingEdge(graph, n3, n2) && subgraphHasCycle(graph, map, n3, n)) {
|
|
return true;
|
|
}
|
|
}
|
|
map.put(n, NodeVisitState.COMPLETE);
|
|
return false;
|
|
}
|
|
|
|
private static boolean canTraverseWithoutReusingEdge(Graph<?> graph, Object obj, @CheckForNull Object obj2) {
|
|
return graph.isDirected() || !Objects.equal(obj2, obj);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static <N> Graph<N> transitiveClosure(Graph<N> graph) {
|
|
StandardMutableGraph build = GraphBuilder.from(graph).allowsSelfLoops(true).build();
|
|
if (graph.isDirected()) {
|
|
for (N n : graph.nodes()) {
|
|
Iterator it = reachableNodes(graph, n).iterator();
|
|
while (it.hasNext()) {
|
|
build.putEdge(n, it.next());
|
|
}
|
|
}
|
|
} else {
|
|
HashSet hashSet = new HashSet();
|
|
for (N n2 : graph.nodes()) {
|
|
if (!hashSet.contains(n2)) {
|
|
Set reachableNodes = reachableNodes(graph, n2);
|
|
hashSet.addAll(reachableNodes);
|
|
int i = 1;
|
|
for (Object obj : reachableNodes) {
|
|
int i2 = i + 1;
|
|
Iterator it2 = Iterables.limit(reachableNodes, i).iterator();
|
|
while (it2.hasNext()) {
|
|
build.putEdge(obj, it2.next());
|
|
}
|
|
i = i2;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return build;
|
|
}
|
|
|
|
public static <N> Set<N> reachableNodes(Graph<N> graph, N n) {
|
|
Preconditions.checkArgument(graph.nodes().contains(n), "Node %s is not an element of this graph.", n);
|
|
return ImmutableSet.copyOf(Traverser.forGraph(graph).breadthFirst((Traverser) n));
|
|
}
|
|
|
|
public static <N> Graph<N> transpose(Graph<N> graph) {
|
|
if (!graph.isDirected()) {
|
|
return graph;
|
|
}
|
|
if (!(graph instanceof TransposedGraph)) {
|
|
return new TransposedGraph(graph);
|
|
}
|
|
return ((TransposedGraph) graph).graph;
|
|
}
|
|
|
|
public static <N, V> ValueGraph<N, V> transpose(ValueGraph<N, V> valueGraph) {
|
|
if (!valueGraph.isDirected()) {
|
|
return valueGraph;
|
|
}
|
|
if (!(valueGraph instanceof TransposedValueGraph)) {
|
|
return new TransposedValueGraph(valueGraph);
|
|
}
|
|
return ((TransposedValueGraph) valueGraph).graph;
|
|
}
|
|
|
|
public static <N, E> Network<N, E> transpose(Network<N, E> network) {
|
|
if (!network.isDirected()) {
|
|
return network;
|
|
}
|
|
if (!(network instanceof TransposedNetwork)) {
|
|
return new TransposedNetwork(network);
|
|
}
|
|
return ((TransposedNetwork) network).network;
|
|
}
|
|
|
|
static <N> EndpointPair<N> transpose(EndpointPair<N> endpointPair) {
|
|
return endpointPair.isOrdered() ? EndpointPair.ordered(endpointPair.target(), endpointPair.source()) : endpointPair;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
/* loaded from: classes3.dex */
|
|
public static class TransposedGraph<N> extends ForwardingGraph<N> {
|
|
private final Graph<N> graph;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
@Override // com.google.common.graph.ForwardingGraph
|
|
public Graph<N> delegate() {
|
|
return this.graph;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.BaseGraph, com.google.common.graph.PredecessorsFunction, com.google.common.graph.Graph
|
|
public /* bridge */ /* synthetic */ Iterable predecessors(Object obj) {
|
|
return predecessors((TransposedGraph<N>) obj);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.BaseGraph, com.google.common.graph.SuccessorsFunction, com.google.common.graph.Graph
|
|
public /* bridge */ /* synthetic */ Iterable successors(Object obj) {
|
|
return successors((TransposedGraph<N>) obj);
|
|
}
|
|
|
|
TransposedGraph(Graph<N> graph) {
|
|
this.graph = graph;
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.BaseGraph, com.google.common.graph.PredecessorsFunction, com.google.common.graph.Graph
|
|
public Set<N> predecessors(N n) {
|
|
return delegate().successors((Graph<N>) n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.BaseGraph, com.google.common.graph.SuccessorsFunction, com.google.common.graph.Graph
|
|
public Set<N> successors(N n) {
|
|
return delegate().predecessors((Graph<N>) n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
|
|
public Set<EndpointPair<N>> incidentEdges(N n) {
|
|
return new IncidentEdgeSet<N>(this, n) { // from class: com.google.common.graph.Graphs.TransposedGraph.1
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
|
|
public Iterator<EndpointPair<N>> iterator() {
|
|
return Iterators.transform(TransposedGraph.this.delegate().incidentEdges(this.node).iterator(), new Function<EndpointPair<N>, EndpointPair<N>>() { // from class: com.google.common.graph.Graphs.TransposedGraph.1.1
|
|
@Override // com.google.common.base.Function
|
|
public EndpointPair<N> apply(EndpointPair<N> endpointPair) {
|
|
return EndpointPair.of((Graph<?>) TransposedGraph.this.delegate(), (Object) endpointPair.nodeV(), (Object) endpointPair.nodeU());
|
|
}
|
|
});
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
|
|
public int inDegree(N n) {
|
|
return delegate().outDegree(n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
|
|
public int outDegree(N n) {
|
|
return delegate().inDegree(n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
|
|
public boolean hasEdgeConnecting(N n, N n2) {
|
|
return delegate().hasEdgeConnecting(n2, n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
|
|
public boolean hasEdgeConnecting(EndpointPair<N> endpointPair) {
|
|
return delegate().hasEdgeConnecting(Graphs.transpose(endpointPair));
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes3.dex */
|
|
private static class TransposedValueGraph<N, V> extends ForwardingValueGraph<N, V> {
|
|
private final ValueGraph<N, V> graph;
|
|
|
|
@Override // com.google.common.graph.ForwardingValueGraph
|
|
ValueGraph<N, V> delegate() {
|
|
return this.graph;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.graph.ForwardingValueGraph, com.google.common.graph.BaseGraph, com.google.common.graph.PredecessorsFunction, com.google.common.graph.Graph
|
|
public /* bridge */ /* synthetic */ Iterable predecessors(Object obj) {
|
|
return predecessors((TransposedValueGraph<N, V>) obj);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.graph.ForwardingValueGraph, com.google.common.graph.BaseGraph, com.google.common.graph.SuccessorsFunction, com.google.common.graph.Graph
|
|
public /* bridge */ /* synthetic */ Iterable successors(Object obj) {
|
|
return successors((TransposedValueGraph<N, V>) obj);
|
|
}
|
|
|
|
TransposedValueGraph(ValueGraph<N, V> valueGraph) {
|
|
this.graph = valueGraph;
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingValueGraph, com.google.common.graph.BaseGraph, com.google.common.graph.PredecessorsFunction, com.google.common.graph.Graph
|
|
public Set<N> predecessors(N n) {
|
|
return delegate().successors((ValueGraph<N, V>) n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingValueGraph, com.google.common.graph.BaseGraph, com.google.common.graph.SuccessorsFunction, com.google.common.graph.Graph
|
|
public Set<N> successors(N n) {
|
|
return delegate().predecessors((ValueGraph<N, V>) n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingValueGraph, com.google.common.graph.AbstractValueGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
|
|
public int inDegree(N n) {
|
|
return delegate().outDegree(n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingValueGraph, com.google.common.graph.AbstractValueGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
|
|
public int outDegree(N n) {
|
|
return delegate().inDegree(n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingValueGraph, com.google.common.graph.AbstractValueGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
|
|
public boolean hasEdgeConnecting(N n, N n2) {
|
|
return delegate().hasEdgeConnecting(n2, n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingValueGraph, com.google.common.graph.AbstractValueGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
|
|
public boolean hasEdgeConnecting(EndpointPair<N> endpointPair) {
|
|
return delegate().hasEdgeConnecting(Graphs.transpose(endpointPair));
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingValueGraph, com.google.common.graph.ValueGraph
|
|
@CheckForNull
|
|
public V edgeValueOrDefault(N n, N n2, @CheckForNull V v) {
|
|
return delegate().edgeValueOrDefault(n2, n, v);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingValueGraph, com.google.common.graph.ValueGraph
|
|
@CheckForNull
|
|
public V edgeValueOrDefault(EndpointPair<N> endpointPair, @CheckForNull V v) {
|
|
return delegate().edgeValueOrDefault(Graphs.transpose(endpointPair), v);
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes3.dex */
|
|
private static class TransposedNetwork<N, E> extends ForwardingNetwork<N, E> {
|
|
private final Network<N, E> network;
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork
|
|
Network<N, E> delegate() {
|
|
return this.network;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.Network, com.google.common.graph.PredecessorsFunction, com.google.common.graph.Graph
|
|
public /* bridge */ /* synthetic */ Iterable predecessors(Object obj) {
|
|
return predecessors((TransposedNetwork<N, E>) obj);
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.Network, com.google.common.graph.SuccessorsFunction, com.google.common.graph.Graph
|
|
public /* bridge */ /* synthetic */ Iterable successors(Object obj) {
|
|
return successors((TransposedNetwork<N, E>) obj);
|
|
}
|
|
|
|
TransposedNetwork(Network<N, E> network) {
|
|
this.network = network;
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.Network, com.google.common.graph.PredecessorsFunction, com.google.common.graph.Graph
|
|
public Set<N> predecessors(N n) {
|
|
return delegate().successors((Network<N, E>) n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.Network, com.google.common.graph.SuccessorsFunction, com.google.common.graph.Graph
|
|
public Set<N> successors(N n) {
|
|
return delegate().predecessors((Network<N, E>) n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.AbstractNetwork, com.google.common.graph.Network
|
|
public int inDegree(N n) {
|
|
return delegate().outDegree(n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.AbstractNetwork, com.google.common.graph.Network
|
|
public int outDegree(N n) {
|
|
return delegate().inDegree(n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.Network
|
|
public Set<E> inEdges(N n) {
|
|
return delegate().outEdges(n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.Network
|
|
public Set<E> outEdges(N n) {
|
|
return delegate().inEdges(n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.Network
|
|
public EndpointPair<N> incidentNodes(E e) {
|
|
EndpointPair<N> incidentNodes = delegate().incidentNodes(e);
|
|
return EndpointPair.of((Network<?, ?>) this.network, (Object) incidentNodes.nodeV(), (Object) incidentNodes.nodeU());
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.AbstractNetwork, com.google.common.graph.Network
|
|
public Set<E> edgesConnecting(N n, N n2) {
|
|
return delegate().edgesConnecting(n2, n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.AbstractNetwork, com.google.common.graph.Network
|
|
public Set<E> edgesConnecting(EndpointPair<N> endpointPair) {
|
|
return delegate().edgesConnecting(Graphs.transpose(endpointPair));
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.AbstractNetwork, com.google.common.graph.Network
|
|
@CheckForNull
|
|
public E edgeConnectingOrNull(N n, N n2) {
|
|
return delegate().edgeConnectingOrNull(n2, n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.AbstractNetwork, com.google.common.graph.Network
|
|
@CheckForNull
|
|
public E edgeConnectingOrNull(EndpointPair<N> endpointPair) {
|
|
return delegate().edgeConnectingOrNull(Graphs.transpose(endpointPair));
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.AbstractNetwork, com.google.common.graph.Network
|
|
public boolean hasEdgeConnecting(N n, N n2) {
|
|
return delegate().hasEdgeConnecting(n2, n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.ForwardingNetwork, com.google.common.graph.AbstractNetwork, com.google.common.graph.Network
|
|
public boolean hasEdgeConnecting(EndpointPair<N> endpointPair) {
|
|
return delegate().hasEdgeConnecting(Graphs.transpose(endpointPair));
|
|
}
|
|
}
|
|
|
|
public static <N> MutableGraph<N> inducedSubgraph(Graph<N> graph, Iterable<? extends N> iterable) {
|
|
StandardMutableGraph standardMutableGraph;
|
|
if (iterable instanceof Collection) {
|
|
standardMutableGraph = (MutableGraph<N>) GraphBuilder.from(graph).expectedNodeCount(((Collection) iterable).size()).build();
|
|
} else {
|
|
standardMutableGraph = (MutableGraph<N>) GraphBuilder.from(graph).build();
|
|
}
|
|
Iterator<? extends N> it = iterable.iterator();
|
|
while (it.hasNext()) {
|
|
standardMutableGraph.addNode(it.next());
|
|
}
|
|
for (N n : standardMutableGraph.nodes()) {
|
|
for (N n2 : graph.successors((Graph<N>) n)) {
|
|
if (standardMutableGraph.nodes().contains(n2)) {
|
|
standardMutableGraph.putEdge(n, n2);
|
|
}
|
|
}
|
|
}
|
|
return standardMutableGraph;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static <N, V> MutableValueGraph<N, V> inducedSubgraph(ValueGraph<N, V> valueGraph, Iterable<? extends N> iterable) {
|
|
MutableValueGraph mutableValueGraph;
|
|
if (iterable instanceof Collection) {
|
|
mutableValueGraph = (MutableValueGraph<N, V>) ValueGraphBuilder.from(valueGraph).expectedNodeCount(((Collection) iterable).size()).build();
|
|
} else {
|
|
mutableValueGraph = (MutableValueGraph<N, V>) ValueGraphBuilder.from(valueGraph).build();
|
|
}
|
|
Iterator<? extends N> it = iterable.iterator();
|
|
while (it.hasNext()) {
|
|
mutableValueGraph.addNode(it.next());
|
|
}
|
|
for (N n : mutableValueGraph.nodes()) {
|
|
for (N n2 : valueGraph.successors((ValueGraph<N, V>) n)) {
|
|
if (mutableValueGraph.nodes().contains(n2)) {
|
|
mutableValueGraph.putEdgeValue(n, n2, java.util.Objects.requireNonNull(valueGraph.edgeValueOrDefault(n, n2, null)));
|
|
}
|
|
}
|
|
}
|
|
return (MutableValueGraph<N, V>) mutableValueGraph;
|
|
}
|
|
|
|
public static <N, E> MutableNetwork<N, E> inducedSubgraph(Network<N, E> network, Iterable<? extends N> iterable) {
|
|
StandardMutableNetwork standardMutableNetwork;
|
|
if (iterable instanceof Collection) {
|
|
standardMutableNetwork = (MutableNetwork<N, E>) NetworkBuilder.from(network).expectedNodeCount(((Collection) iterable).size()).build();
|
|
} else {
|
|
standardMutableNetwork = (MutableNetwork<N, E>) NetworkBuilder.from(network).build();
|
|
}
|
|
Iterator<? extends N> it = iterable.iterator();
|
|
while (it.hasNext()) {
|
|
standardMutableNetwork.addNode(it.next());
|
|
}
|
|
for (E e : standardMutableNetwork.nodes()) {
|
|
for (E e2 : network.outEdges(e)) {
|
|
N adjacentNode = network.incidentNodes(e2).adjacentNode(e);
|
|
if (standardMutableNetwork.nodes().contains(adjacentNode)) {
|
|
standardMutableNetwork.addEdge(e, adjacentNode, e2);
|
|
}
|
|
}
|
|
}
|
|
return standardMutableNetwork;
|
|
}
|
|
|
|
public static <N> MutableGraph<N> copyOf(Graph<N> graph) {
|
|
MutableGraph<N> mutableGraph = (MutableGraph<N>) GraphBuilder.from(graph).expectedNodeCount(graph.nodes().size()).build();
|
|
Iterator<N> it = graph.nodes().iterator();
|
|
while (it.hasNext()) {
|
|
mutableGraph.addNode(it.next());
|
|
}
|
|
for (EndpointPair<N> endpointPair : graph.edges()) {
|
|
mutableGraph.putEdge(endpointPair.nodeU(), endpointPair.nodeV());
|
|
}
|
|
return mutableGraph;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public static <N, V> MutableValueGraph<N, V> copyOf(ValueGraph<N, V> valueGraph) {
|
|
StandardMutableValueGraph standardMutableValueGraph = (MutableValueGraph<N, V>) ValueGraphBuilder.from(valueGraph).expectedNodeCount(valueGraph.nodes().size()).build();
|
|
Iterator<N> it = valueGraph.nodes().iterator();
|
|
while (it.hasNext()) {
|
|
standardMutableValueGraph.addNode(it.next());
|
|
}
|
|
for (EndpointPair<N> endpointPair : valueGraph.edges()) {
|
|
standardMutableValueGraph.putEdgeValue(endpointPair.nodeU(), endpointPair.nodeV(), java.util.Objects.requireNonNull(valueGraph.edgeValueOrDefault(endpointPair.nodeU(), endpointPair.nodeV(), null)));
|
|
}
|
|
return standardMutableValueGraph;
|
|
}
|
|
|
|
public static <N, E> MutableNetwork<N, E> copyOf(Network<N, E> network) {
|
|
MutableNetwork<N, E> mutableNetwork = (MutableNetwork<N, E>) NetworkBuilder.from(network).expectedNodeCount(network.nodes().size()).expectedEdgeCount(network.edges().size()).build();
|
|
Iterator<N> it = network.nodes().iterator();
|
|
while (it.hasNext()) {
|
|
mutableNetwork.addNode(it.next());
|
|
}
|
|
for (E e : network.edges()) {
|
|
EndpointPair<N> incidentNodes = network.incidentNodes(e);
|
|
mutableNetwork.addEdge(incidentNodes.nodeU(), incidentNodes.nodeV(), e);
|
|
}
|
|
return mutableNetwork;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static int checkNonNegative(int i) {
|
|
Preconditions.checkArgument(i >= 0, "Not true that %s is non-negative.", i);
|
|
return i;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static long checkNonNegative(long j) {
|
|
Preconditions.checkArgument(j >= 0, "Not true that %s is non-negative.", j);
|
|
return j;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static int checkPositive(int i) {
|
|
Preconditions.checkArgument(i > 0, "Not true that %s is positive.", i);
|
|
return i;
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static long checkPositive(long j) {
|
|
Preconditions.checkArgument(j > 0, "Not true that %s is positive.", j);
|
|
return j;
|
|
}
|
|
}
|