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; import javax.annotation.CheckForNull; @ElementTypesAreNonnullByDefault /* loaded from: classes3.dex */ class StandardValueGraph extends AbstractValueGraph { private final boolean allowsSelfLoops; long edgeCount; private final boolean isDirected; final MapIteratorCache> nodeConnections; private final ElementOrder nodeOrder; @Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph public boolean allowsSelfLoops() { return this.allowsSelfLoops; } @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 isDirected() { return this.isDirected; } @Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph public ElementOrder nodeOrder() { return this.nodeOrder; } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.graph.BaseGraph, com.google.common.graph.PredecessorsFunction, com.google.common.graph.Graph public /* bridge */ /* synthetic */ Iterable predecessors(Object obj) { return predecessors((StandardValueGraph) obj); } /* JADX WARN: Multi-variable type inference failed */ @Override // com.google.common.graph.BaseGraph, com.google.common.graph.SuccessorsFunction, com.google.common.graph.Graph 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, com.google.common.graph.Graph public Set predecessors(N n) { return checkedConnections(n).predecessors(); } @Override // com.google.common.graph.BaseGraph, com.google.common.graph.SuccessorsFunction, com.google.common.graph.Graph 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) { final GraphConnections checkedConnections = checkedConnections(n); return new IncidentEdgeSet(this, this, n) { // from class: com.google.common.graph.StandardValueGraph.1 @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator> iterator() { return checkedConnections.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 hasEdgeConnectingInternal(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) && hasEdgeConnectingInternal(endpointPair.nodeU(), endpointPair.nodeV()); } /* JADX WARN: Multi-variable type inference failed */ @CheckForNull public V edgeValueOrDefault(N n, N n2, @CheckForNull V v) { return (V) edgeValueOrDefaultInternal(Preconditions.checkNotNull(n), Preconditions.checkNotNull(n2), v); } @CheckForNull public V edgeValueOrDefault(EndpointPair endpointPair, @CheckForNull V v) { validateEndpoints(endpointPair); return edgeValueOrDefaultInternal(endpointPair.nodeU(), endpointPair.nodeV(), v); } private final GraphConnections checkedConnections(N n) { GraphConnections graphConnections = this.nodeConnections.get(n); if (graphConnections != null) { return graphConnections; } Preconditions.checkNotNull(n); String valueOf = String.valueOf(n); throw new IllegalArgumentException(new StringBuilder(String.valueOf(valueOf).length() + 38).append("Node ").append(valueOf).append(" is not an element of this graph.").toString()); } /* JADX INFO: Access modifiers changed from: package-private */ public final boolean containsNode(@CheckForNull N n) { return this.nodeConnections.containsKey(n); } private final boolean hasEdgeConnectingInternal(N n, N n2) { GraphConnections graphConnections = this.nodeConnections.get(n); return graphConnections != null && graphConnections.successors().contains(n2); } @CheckForNull private final V edgeValueOrDefaultInternal(N n, N n2, @CheckForNull V v) { GraphConnections graphConnections = this.nodeConnections.get(n); V value = graphConnections == null ? null : graphConnections.value(n2); return value == null ? v : value; } }