package com.google.common.graph; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import java.util.Map; import java.util.Set; import java.util.TreeMap; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public class StandardNetwork extends AbstractNetwork { private final boolean allowsParallelEdges; private final boolean allowsSelfLoops; private final ElementOrder edgeOrder; protected final MapIteratorCache edgeToReferenceNode; private final boolean isDirected; protected final MapIteratorCache> nodeConnections; private final ElementOrder nodeOrder; /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.graph.PredecessorsFunction public /* bridge */ /* synthetic */ Iterable predecessors(Object obj) { return predecessors((StandardNetwork) obj); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.graph.SuccessorsFunction public /* bridge */ /* synthetic */ Iterable successors(Object obj) { return successors((StandardNetwork) obj); } /* JADX INFO: Access modifiers changed from: package-private */ public StandardNetwork(NetworkBuilder networkBuilder) { this(networkBuilder, networkBuilder.nodeOrder.createMap(networkBuilder.expectedNodeCount.or((Optional) 10).intValue()), networkBuilder.edgeOrder.createMap(networkBuilder.expectedEdgeCount.or((Optional) 20).intValue())); } /* JADX INFO: Access modifiers changed from: package-private */ public StandardNetwork(NetworkBuilder networkBuilder, Map> map, Map map2) { MapIteratorCache> mapIteratorCache; this.isDirected = networkBuilder.directed; this.allowsParallelEdges = networkBuilder.allowsParallelEdges; this.allowsSelfLoops = networkBuilder.allowsSelfLoops; this.nodeOrder = (ElementOrder) networkBuilder.nodeOrder.cast(); this.edgeOrder = (ElementOrder) networkBuilder.edgeOrder.cast(); if (map instanceof TreeMap) { mapIteratorCache = new MapRetrievalCache<>(map); } else { mapIteratorCache = new MapIteratorCache<>(map); } this.nodeConnections = mapIteratorCache; this.edgeToReferenceNode = new MapIteratorCache<>(map2); } @Override // com.google.common.graph.Network public Set nodes() { return this.nodeConnections.unmodifiableKeySet(); } @Override // com.google.common.graph.Network public Set edges() { return this.edgeToReferenceNode.unmodifiableKeySet(); } @Override // com.google.common.graph.Network public Set incidentEdges(N n) { return checkedConnections(n).incidentEdges(); } @Override // com.google.common.graph.Network public EndpointPair incidentNodes(E e) { N checkedReferenceNode = checkedReferenceNode(e); return EndpointPair.of(this, checkedReferenceNode, this.nodeConnections.get(checkedReferenceNode).adjacentNode(e)); } @Override // com.google.common.graph.Network public Set adjacentNodes(N n) { return checkedConnections(n).adjacentNodes(); } @Override // com.google.common.graph.AbstractNetwork, com.google.common.graph.Network public Set edgesConnecting(N n, N n2) { NetworkConnections checkedConnections = checkedConnections(n); if (!this.allowsSelfLoops && n == n2) { return ImmutableSet.of(); } Preconditions.checkArgument(containsNode(n2), "Node %s is not an element of this graph.", n2); return checkedConnections.edgesConnecting(n2); } @Override // com.google.common.graph.Network public Set inEdges(N n) { return checkedConnections(n).inEdges(); } @Override // com.google.common.graph.Network public Set outEdges(N n) { return checkedConnections(n).outEdges(); } @Override // com.google.common.graph.Network, com.google.common.graph.PredecessorsFunction public Set predecessors(N n) { return checkedConnections(n).predecessors(); } @Override // com.google.common.graph.Network, com.google.common.graph.SuccessorsFunction public Set successors(N n) { return checkedConnections(n).successors(); } protected final NetworkConnections checkedConnections(N n) { NetworkConnections networkConnections = this.nodeConnections.get(n); if (networkConnections != null) { return networkConnections; } Preconditions.checkNotNull(n); throw new IllegalArgumentException(String.format("Node %s is not an element of this graph.", n)); } protected final N checkedReferenceNode(E e) { N n = this.edgeToReferenceNode.get(e); if (n != null) { return n; } Preconditions.checkNotNull(e); throw new IllegalArgumentException(String.format("Edge %s is not an element of this graph.", e)); } /* JADX INFO: Access modifiers changed from: protected */ public final boolean containsNode(N n) { return this.nodeConnections.containsKey(n); } /* JADX INFO: Access modifiers changed from: protected */ public final boolean containsEdge(E e) { return this.edgeToReferenceNode.containsKey(e); } @Override // com.google.common.graph.Network public ElementOrder nodeOrder() { return this.nodeOrder; } @Override // com.google.common.graph.Network public boolean isDirected() { return this.isDirected; } @Override // com.google.common.graph.Network public ElementOrder edgeOrder() { return this.edgeOrder; } @Override // com.google.common.graph.Network public boolean allowsSelfLoops() { return this.allowsSelfLoops; } @Override // com.google.common.graph.Network public boolean allowsParallelEdges() { return this.allowsParallelEdges; } }