package com.google.common.graph; import com.google.common.base.Optional; import com.google.common.base.Preconditions; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.TreeMap; /* loaded from: classes2.dex */ class StandardValueGraph extends AbstractValueGraph { private final boolean allowsSelfLoops; protected long edgeCount; 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((StandardValueGraph) obj); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.graph.SuccessorsFunction public /* bridge */ /* synthetic */ Iterable successors(Object obj) { return successors((StandardValueGraph) obj); } /* JADX INFO: Access modifiers changed from: package-private */ public StandardValueGraph(AbstractGraphBuilder abstractGraphBuilder) { this(abstractGraphBuilder, abstractGraphBuilder.nodeOrder.createMap(abstractGraphBuilder.expectedNodeCount.or((Optional) 10).intValue()), 0L); } /* JADX INFO: Access modifiers changed from: package-private */ public StandardValueGraph(AbstractGraphBuilder abstractGraphBuilder, Map> map, long j) { MapIteratorCache> mapIteratorCache; this.isDirected = abstractGraphBuilder.directed; this.allowsSelfLoops = abstractGraphBuilder.allowsSelfLoops; this.nodeOrder = (ElementOrder) abstractGraphBuilder.nodeOrder.cast(); if (map instanceof TreeMap) { mapIteratorCache = new MapRetrievalCache<>(map); } else { mapIteratorCache = new MapIteratorCache<>(map); } this.nodeConnections = mapIteratorCache; this.edgeCount = Graphs.checkNonNegative(j); } @Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph public Set nodes() { return this.nodeConnections.unmodifiableKeySet(); } @Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph public Set adjacentNodes(N n) { return checkedConnections(n).adjacentNodes(); } @Override // com.google.common.graph.BaseGraph, com.google.common.graph.PredecessorsFunction public Set predecessors(N n) { return checkedConnections(n).predecessors(); } @Override // com.google.common.graph.BaseGraph, com.google.common.graph.SuccessorsFunction public Set successors(N n) { return checkedConnections(n).successors(); } @Override // com.google.common.graph.AbstractValueGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph public Set> incidentEdges(N n) { return new IncidentEdgeSet(this, this, n, checkedConnections(n)) { // from class: com.google.common.graph.StandardValueGraph.1 final GraphConnections val$connections; { this.val$connections = r4; } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator> iterator() { return this.val$connections.incidentEdgeIterator(this.node); } }; } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.graph.AbstractValueGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph public boolean hasEdgeConnecting(N n, N n2) { return hasEdgeConnecting_internal(Preconditions.checkNotNull(n), Preconditions.checkNotNull(n2)); } @Override // com.google.common.graph.AbstractValueGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph public boolean hasEdgeConnecting(EndpointPair endpointPair) { Preconditions.checkNotNull(endpointPair); return isOrderingCompatible(endpointPair) && hasEdgeConnecting_internal(endpointPair.nodeU(), endpointPair.nodeV()); } /* JADX WARN: Multi-variable type inference failed */ public V edgeValueOrDefault(N n, N n2, V v) { return (V) edgeValueOrDefault_internal(Preconditions.checkNotNull(n), Preconditions.checkNotNull(n2), v); } public V edgeValueOrDefault(EndpointPair endpointPair, V v) { validateEndpoints(endpointPair); return edgeValueOrDefault_internal(endpointPair.nodeU(), endpointPair.nodeV(), v); } protected final GraphConnections checkedConnections(N n) { GraphConnections graphConnections = this.nodeConnections.get(n); if (graphConnections != null) { return graphConnections; } Preconditions.checkNotNull(n); String valueOf = String.valueOf(n); StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 38); sb.append("Node "); sb.append(valueOf); sb.append(" is not an element of this graph."); throw new IllegalArgumentException(sb.toString()); } /* JADX INFO: Access modifiers changed from: protected */ public final boolean containsNode(N n) { return this.nodeConnections.containsKey(n); } protected final boolean hasEdgeConnecting_internal(N n, N n2) { GraphConnections graphConnections = this.nodeConnections.get(n); return graphConnections != null && graphConnections.successors().contains(n2); } protected final V edgeValueOrDefault_internal(N n, N n2, V v) { GraphConnections graphConnections = this.nodeConnections.get(n); V value = graphConnections == null ? null : graphConnections.value(n2); return value == null ? v : value; } @Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph public ElementOrder nodeOrder() { return this.nodeOrder; } @Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph public boolean isDirected() { return this.isDirected; } @Override // com.google.common.graph.AbstractBaseGraph protected long edgeCount() { return this.edgeCount; } @Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph public boolean allowsSelfLoops() { return this.allowsSelfLoops; } }