what-the-bank/sources/com/google/common/graph/StandardValueGraph.java

158 lines
6.5 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
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<N, V> extends AbstractValueGraph<N, V> {
private final boolean allowsSelfLoops;
protected long edgeCount;
private final boolean isDirected;
protected final MapIteratorCache<N, GraphConnections<N, V>> nodeConnections;
private final ElementOrder<N> nodeOrder;
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.graph.PredecessorsFunction
public /* bridge */ /* synthetic */ Iterable predecessors(Object obj) {
return predecessors((StandardValueGraph<N, V>) obj);
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.graph.SuccessorsFunction
public /* bridge */ /* synthetic */ Iterable successors(Object obj) {
return successors((StandardValueGraph<N, V>) obj);
}
/* JADX INFO: Access modifiers changed from: package-private */
public StandardValueGraph(AbstractGraphBuilder<? super N> abstractGraphBuilder) {
this(abstractGraphBuilder, abstractGraphBuilder.nodeOrder.createMap(abstractGraphBuilder.expectedNodeCount.or((Optional<Integer>) 10).intValue()), 0L);
}
/* JADX INFO: Access modifiers changed from: package-private */
public StandardValueGraph(AbstractGraphBuilder<? super N> abstractGraphBuilder, Map<N, GraphConnections<N, V>> map, long j) {
MapIteratorCache<N, GraphConnections<N, V>> mapIteratorCache;
this.isDirected = abstractGraphBuilder.directed;
this.allowsSelfLoops = abstractGraphBuilder.allowsSelfLoops;
this.nodeOrder = (ElementOrder<N>) 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<N> nodes() {
return this.nodeConnections.unmodifiableKeySet();
}
@Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph
public Set<N> adjacentNodes(N n) {
return checkedConnections(n).adjacentNodes();
}
@Override // com.google.common.graph.BaseGraph, com.google.common.graph.PredecessorsFunction
public Set<N> predecessors(N n) {
return checkedConnections(n).predecessors();
}
@Override // com.google.common.graph.BaseGraph, com.google.common.graph.SuccessorsFunction
public Set<N> 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<EndpointPair<N>> incidentEdges(N n) {
return new IncidentEdgeSet<N>(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<EndpointPair<N>> 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<N> 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<N> endpointPair, V v) {
validateEndpoints(endpointPair);
return edgeValueOrDefault_internal(endpointPair.nodeU(), endpointPair.nodeV(), v);
}
protected final GraphConnections<N, V> checkedConnections(N n) {
GraphConnections<N, V> 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<N, V> graphConnections = this.nodeConnections.get(n);
return graphConnections != null && graphConnections.successors().contains(n2);
}
protected final V edgeValueOrDefault_internal(N n, N n2, V v) {
GraphConnections<N, V> 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<N> 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;
}
}