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

160 lines
7.0 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.graph;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.graph.GraphConstants;
import java.util.Set;
/* loaded from: classes2.dex */
public class ImmutableGraph<N> extends ForwardingGraph<N> {
private final BaseGraph<N> backingGraph;
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.BaseGraph, com.google.common.graph.Graph
public /* bridge */ /* synthetic */ Set adjacentNodes(Object obj) {
return super.adjacentNodes(obj);
}
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.BaseGraph, com.google.common.graph.Graph
public /* bridge */ /* synthetic */ boolean allowsSelfLoops() {
return super.allowsSelfLoops();
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
public /* bridge */ /* synthetic */ int degree(Object obj) {
return super.degree(obj);
}
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
public /* bridge */ /* synthetic */ boolean hasEdgeConnecting(EndpointPair endpointPair) {
return super.hasEdgeConnecting(endpointPair);
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
public /* bridge */ /* synthetic */ boolean hasEdgeConnecting(Object obj, Object obj2) {
return super.hasEdgeConnecting(obj, obj2);
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
public /* bridge */ /* synthetic */ int inDegree(Object obj) {
return super.inDegree(obj);
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
public /* bridge */ /* synthetic */ Set incidentEdges(Object obj) {
return super.incidentEdges(obj);
}
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.BaseGraph, com.google.common.graph.Graph
public /* bridge */ /* synthetic */ boolean isDirected() {
return super.isDirected();
}
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.BaseGraph, com.google.common.graph.Graph
public /* bridge */ /* synthetic */ ElementOrder nodeOrder() {
return super.nodeOrder();
}
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.BaseGraph, com.google.common.graph.Graph
public /* bridge */ /* synthetic */ Set nodes() {
return super.nodes();
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
public /* bridge */ /* synthetic */ int outDegree(Object obj) {
return super.outDegree(obj);
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.BaseGraph, com.google.common.graph.PredecessorsFunction
public /* bridge */ /* synthetic */ Set predecessors(Object obj) {
return super.predecessors((ImmutableGraph<N>) obj);
}
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.BaseGraph, com.google.common.graph.SuccessorsFunction
public /* bridge */ /* synthetic */ Set successors(Object obj) {
return super.successors((ImmutableGraph<N>) obj);
}
/* JADX INFO: Access modifiers changed from: package-private */
public ImmutableGraph(BaseGraph<N> baseGraph) {
this.backingGraph = baseGraph;
}
public static <N> ImmutableGraph<N> copyOf(Graph<N> graph) {
if (graph instanceof ImmutableGraph) {
return (ImmutableGraph) graph;
}
return new ImmutableGraph<>(new StandardValueGraph(GraphBuilder.from(graph), getNodeConnections(graph), graph.edges().size()));
}
@Deprecated
public static <N> ImmutableGraph<N> copyOf(ImmutableGraph<N> immutableGraph) {
return (ImmutableGraph) Preconditions.checkNotNull(immutableGraph);
}
@Override // com.google.common.graph.ForwardingGraph, com.google.common.graph.AbstractGraph, com.google.common.graph.AbstractBaseGraph, com.google.common.graph.BaseGraph
public ElementOrder<N> incidentEdgeOrder() {
return ElementOrder.stable();
}
private static <N> ImmutableMap<N, GraphConnections<N, GraphConstants.Presence>> getNodeConnections(Graph<N> graph) {
ImmutableMap.Builder builder = ImmutableMap.builder();
for (N n : graph.nodes()) {
builder.put(n, connectionsOf(graph, n));
}
return builder.build();
}
private static <N> GraphConnections<N, GraphConstants.Presence> connectionsOf(Graph<N> graph, N n) {
Function constant = Functions.constant(GraphConstants.Presence.EDGE_EXISTS);
if (graph.isDirected()) {
return DirectedGraphConnections.ofImmutable(n, graph.incidentEdges(n), constant);
}
return UndirectedGraphConnections.ofImmutable(Maps.asMap(graph.adjacentNodes(n), constant));
}
/* loaded from: classes2.dex */
public static class Builder<N> {
private final MutableGraph<N> mutableGraph;
/* JADX INFO: Access modifiers changed from: package-private */
public Builder(GraphBuilder<N> graphBuilder) {
this.mutableGraph = graphBuilder.copy().incidentEdgeOrder(ElementOrder.stable()).build();
}
public Builder<N> addNode(N n) {
this.mutableGraph.addNode(n);
return this;
}
public Builder<N> putEdge(N n, N n2) {
this.mutableGraph.putEdge(n, n2);
return this;
}
public Builder<N> putEdge(EndpointPair<N> endpointPair) {
this.mutableGraph.putEdge(endpointPair);
return this;
}
public ImmutableGraph<N> build() {
return ImmutableGraph.copyOf(this.mutableGraph);
}
}
@Override // com.google.common.graph.ForwardingGraph
protected BaseGraph<N> delegate() {
return this.backingGraph;
}
}