mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-27 17:42:33 -06:00
153 lines
6.8 KiB
Java
153 lines
6.8 KiB
Java
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<N, V> extends AbstractValueGraph<N, V> {
|
|
private final boolean allowsSelfLoops;
|
|
long edgeCount;
|
|
private final boolean isDirected;
|
|
final MapIteratorCache<N, GraphConnections<N, V>> nodeConnections;
|
|
private final ElementOrder<N> 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<N> 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<N, V>) 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<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, com.google.common.graph.Graph
|
|
public Set<N> 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<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) {
|
|
final GraphConnections<N, V> checkedConnections = checkedConnections(n);
|
|
return new IncidentEdgeSet<N>(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<EndpointPair<N>> 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<N> 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<N> endpointPair, @CheckForNull V v) {
|
|
validateEndpoints(endpointPair);
|
|
return edgeValueOrDefaultInternal(endpointPair.nodeU(), endpointPair.nodeV(), v);
|
|
}
|
|
|
|
private 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);
|
|
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<N, V> 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<N, V> graphConnections = this.nodeConnections.get(n);
|
|
V value = graphConnections == null ? null : graphConnections.value(n2);
|
|
return value == null ? v : value;
|
|
}
|
|
}
|