mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-26 17:12:31 -06:00
260 lines
11 KiB
Java
260 lines
11 KiB
Java
|
package com.google.common.graph;
|
||
|
|
||
|
import com.google.common.base.Function;
|
||
|
import com.google.common.base.Preconditions;
|
||
|
import com.google.common.base.Predicate;
|
||
|
import com.google.common.collect.ImmutableSet;
|
||
|
import com.google.common.collect.Iterators;
|
||
|
import com.google.common.collect.Maps;
|
||
|
import com.google.common.collect.Sets;
|
||
|
import com.google.common.math.IntMath;
|
||
|
import java.util.AbstractSet;
|
||
|
import java.util.Collections;
|
||
|
import java.util.Iterator;
|
||
|
import java.util.Map;
|
||
|
import java.util.Set;
|
||
|
import javax.annotation.CheckForNull;
|
||
|
|
||
|
@ElementTypesAreNonnullByDefault
|
||
|
/* loaded from: classes3.dex */
|
||
|
public abstract class AbstractNetwork<N, E> implements Network<N, E> {
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* renamed from: com.google.common.graph.AbstractNetwork$1, reason: invalid class name */
|
||
|
/* loaded from: classes3.dex */
|
||
|
public class AnonymousClass1 extends AbstractGraph<N> {
|
||
|
AnonymousClass1() {
|
||
|
}
|
||
|
|
||
|
@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((AnonymousClass1) obj);
|
||
|
}
|
||
|
|
||
|
@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((AnonymousClass1) obj);
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph
|
||
|
public Set<N> nodes() {
|
||
|
return AbstractNetwork.this.nodes();
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
|
||
|
public Set<EndpointPair<N>> edges() {
|
||
|
if (AbstractNetwork.this.allowsParallelEdges()) {
|
||
|
return super.edges();
|
||
|
}
|
||
|
return new AbstractSet<EndpointPair<N>>() { // from class: com.google.common.graph.AbstractNetwork.1.1
|
||
|
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
|
||
|
public Iterator<EndpointPair<N>> iterator() {
|
||
|
return Iterators.transform(AbstractNetwork.this.edges().iterator(), new Function<E, EndpointPair<N>>() { // from class: com.google.common.graph.AbstractNetwork.1.1.1
|
||
|
@Override // com.google.common.base.Function
|
||
|
public /* bridge */ /* synthetic */ Object apply(Object obj) {
|
||
|
return apply((C00671) obj);
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.base.Function
|
||
|
public EndpointPair<N> apply(E e) {
|
||
|
return AbstractNetwork.this.incidentNodes(e);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
||
|
public int size() {
|
||
|
return AbstractNetwork.this.edges().size();
|
||
|
}
|
||
|
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
||
|
public boolean contains(@CheckForNull Object obj) {
|
||
|
if (!(obj instanceof EndpointPair)) {
|
||
|
return false;
|
||
|
}
|
||
|
EndpointPair<?> endpointPair = (EndpointPair) obj;
|
||
|
return AnonymousClass1.this.isOrderingCompatible(endpointPair) && AnonymousClass1.this.nodes().contains(endpointPair.nodeU()) && AnonymousClass1.this.successors((AnonymousClass1) endpointPair.nodeU()).contains(endpointPair.nodeV());
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph
|
||
|
public ElementOrder<N> nodeOrder() {
|
||
|
return AbstractNetwork.this.nodeOrder();
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
|
||
|
public ElementOrder<N> incidentEdgeOrder() {
|
||
|
return ElementOrder.unordered();
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph
|
||
|
public boolean isDirected() {
|
||
|
return AbstractNetwork.this.isDirected();
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph
|
||
|
public boolean allowsSelfLoops() {
|
||
|
return AbstractNetwork.this.allowsSelfLoops();
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.BaseGraph, com.google.common.graph.Graph
|
||
|
public Set<N> adjacentNodes(N n) {
|
||
|
return AbstractNetwork.this.adjacentNodes(n);
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.BaseGraph, com.google.common.graph.PredecessorsFunction, com.google.common.graph.Graph
|
||
|
public Set<N> predecessors(N n) {
|
||
|
return AbstractNetwork.this.predecessors((Object) n);
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.BaseGraph, com.google.common.graph.SuccessorsFunction, com.google.common.graph.Graph
|
||
|
public Set<N> successors(N n) {
|
||
|
return AbstractNetwork.this.successors((Object) n);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
public Graph<N> asGraph() {
|
||
|
return new AnonymousClass1();
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
public int degree(N n) {
|
||
|
if (isDirected()) {
|
||
|
return IntMath.saturatedAdd(inEdges(n).size(), outEdges(n).size());
|
||
|
}
|
||
|
return IntMath.saturatedAdd(incidentEdges(n).size(), edgesConnecting(n, n).size());
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
public int inDegree(N n) {
|
||
|
return isDirected() ? inEdges(n).size() : degree(n);
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
public int outDegree(N n) {
|
||
|
return isDirected() ? outEdges(n).size() : degree(n);
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
public Set<E> adjacentEdges(E e) {
|
||
|
EndpointPair<N> incidentNodes = incidentNodes(e);
|
||
|
return Sets.difference(Sets.union(incidentEdges(incidentNodes.nodeU()), incidentEdges(incidentNodes.nodeV())), ImmutableSet.of((Object) e));
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
public Set<E> edgesConnecting(N n, N n2) {
|
||
|
Set<E> outEdges = outEdges(n);
|
||
|
Set<E> inEdges = inEdges(n2);
|
||
|
if (outEdges.size() <= inEdges.size()) {
|
||
|
return Collections.unmodifiableSet(Sets.filter(outEdges, connectedPredicate(n, n2)));
|
||
|
}
|
||
|
return Collections.unmodifiableSet(Sets.filter(inEdges, connectedPredicate(n2, n)));
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
public Set<E> edgesConnecting(EndpointPair<N> endpointPair) {
|
||
|
validateEndpoints(endpointPair);
|
||
|
return edgesConnecting(endpointPair.nodeU(), endpointPair.nodeV());
|
||
|
}
|
||
|
|
||
|
private Predicate<E> connectedPredicate(final N n, final N n2) {
|
||
|
return new Predicate<E>() { // from class: com.google.common.graph.AbstractNetwork.2
|
||
|
/* JADX WARN: Multi-variable type inference failed */
|
||
|
@Override // com.google.common.base.Predicate
|
||
|
public boolean apply(E e) {
|
||
|
return AbstractNetwork.this.incidentNodes(e).adjacentNode(n).equals(n2);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
@CheckForNull
|
||
|
public E edgeConnectingOrNull(N n, N n2) {
|
||
|
Set<E> edgesConnecting = edgesConnecting(n, n2);
|
||
|
int size = edgesConnecting.size();
|
||
|
if (size == 0) {
|
||
|
return null;
|
||
|
}
|
||
|
if (size == 1) {
|
||
|
return edgesConnecting.iterator().next();
|
||
|
}
|
||
|
throw new IllegalArgumentException(String.format("Cannot call edgeConnecting() when parallel edges exist between %s and %s. Consider calling edgesConnecting() instead.", n, n2));
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
@CheckForNull
|
||
|
public E edgeConnectingOrNull(EndpointPair<N> endpointPair) {
|
||
|
validateEndpoints(endpointPair);
|
||
|
return edgeConnectingOrNull(endpointPair.nodeU(), endpointPair.nodeV());
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
public boolean hasEdgeConnecting(N n, N n2) {
|
||
|
Preconditions.checkNotNull(n);
|
||
|
Preconditions.checkNotNull(n2);
|
||
|
return nodes().contains(n) && successors((Object) n).contains(n2);
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
public boolean hasEdgeConnecting(EndpointPair<N> endpointPair) {
|
||
|
Preconditions.checkNotNull(endpointPair);
|
||
|
if (isOrderingCompatible(endpointPair)) {
|
||
|
return hasEdgeConnecting(endpointPair.nodeU(), endpointPair.nodeV());
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: protected */
|
||
|
public final void validateEndpoints(EndpointPair<?> endpointPair) {
|
||
|
Preconditions.checkNotNull(endpointPair);
|
||
|
Preconditions.checkArgument(isOrderingCompatible(endpointPair), "Mismatch: unordered endpoints cannot be used with directed graphs");
|
||
|
}
|
||
|
|
||
|
protected final boolean isOrderingCompatible(EndpointPair<?> endpointPair) {
|
||
|
return endpointPair.isOrdered() || !isDirected();
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
public final boolean equals(@CheckForNull Object obj) {
|
||
|
if (obj == this) {
|
||
|
return true;
|
||
|
}
|
||
|
if (!(obj instanceof Network)) {
|
||
|
return false;
|
||
|
}
|
||
|
Network network = (Network) obj;
|
||
|
return isDirected() == network.isDirected() && nodes().equals(network.nodes()) && edgeIncidentNodesMap(this).equals(edgeIncidentNodesMap(network));
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.graph.Network
|
||
|
public final int hashCode() {
|
||
|
return edgeIncidentNodesMap(this).hashCode();
|
||
|
}
|
||
|
|
||
|
public String toString() {
|
||
|
boolean isDirected = isDirected();
|
||
|
boolean allowsParallelEdges = allowsParallelEdges();
|
||
|
boolean allowsSelfLoops = allowsSelfLoops();
|
||
|
String valueOf = String.valueOf(nodes());
|
||
|
String valueOf2 = String.valueOf(edgeIncidentNodesMap(this));
|
||
|
return new StringBuilder(String.valueOf(valueOf).length() + 87 + String.valueOf(valueOf2).length()).append("isDirected: ").append(isDirected).append(", allowsParallelEdges: ").append(allowsParallelEdges).append(", allowsSelfLoops: ").append(allowsSelfLoops).append(", nodes: ").append(valueOf).append(", edges: ").append(valueOf2).toString();
|
||
|
}
|
||
|
|
||
|
private static <N, E> Map<E, EndpointPair<N>> edgeIncidentNodesMap(final Network<N, E> network) {
|
||
|
return Maps.asMap(network.edges(), new Function<E, EndpointPair<N>>() { // from class: com.google.common.graph.AbstractNetwork.3
|
||
|
@Override // com.google.common.base.Function
|
||
|
public /* bridge */ /* synthetic */ Object apply(Object obj) {
|
||
|
return apply((AnonymousClass3) obj);
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.base.Function
|
||
|
public EndpointPair<N> apply(E e) {
|
||
|
return Network.this.incidentNodes(e);
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
}
|