109 lines
4.0 KiB
Java
109 lines
4.0 KiB
Java
package com.google.common.graph;
|
|
|
|
import com.google.common.base.Preconditions;
|
|
import com.google.common.collect.HashMultiset;
|
|
import com.google.common.collect.ImmutableMap;
|
|
import com.google.common.collect.Multiset;
|
|
import java.lang.ref.Reference;
|
|
import java.lang.ref.SoftReference;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
/* loaded from: classes2.dex */
|
|
public final class UndirectedMultiNetworkConnections<N, E> extends AbstractUndirectedNetworkConnections<N, E> {
|
|
private transient Reference<Multiset<N>> adjacentNodesReference;
|
|
|
|
private UndirectedMultiNetworkConnections(Map<E, N> map) {
|
|
super(map);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static <N, E> UndirectedMultiNetworkConnections<N, E> of() {
|
|
return new UndirectedMultiNetworkConnections<>(new HashMap(2, 1.0f));
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: package-private */
|
|
public static <N, E> UndirectedMultiNetworkConnections<N, E> ofImmutable(Map<E, N> map) {
|
|
return new UndirectedMultiNetworkConnections<>(ImmutableMap.copyOf((Map) map));
|
|
}
|
|
|
|
@Override // com.google.common.graph.NetworkConnections
|
|
public final Set<N> adjacentNodes() {
|
|
return Collections.unmodifiableSet(adjacentNodesMultiset().elementSet());
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public Multiset<N> adjacentNodesMultiset() {
|
|
Multiset<N> multiset = (Multiset) getReference(this.adjacentNodesReference);
|
|
if (multiset != null) {
|
|
return multiset;
|
|
}
|
|
HashMultiset create = HashMultiset.create(this.incidentEdgeMap.values());
|
|
this.adjacentNodesReference = new SoftReference(create);
|
|
return create;
|
|
}
|
|
|
|
@Override // com.google.common.graph.NetworkConnections
|
|
public final Set<E> edgesConnecting(N n) {
|
|
return new MultiEdgesConnecting<E>(this, this.incidentEdgeMap, n, n) { // from class: com.google.common.graph.UndirectedMultiNetworkConnections.1
|
|
final UndirectedMultiNetworkConnections this$0;
|
|
final Object val$node;
|
|
|
|
{
|
|
this.this$0 = this;
|
|
this.val$node = n;
|
|
}
|
|
|
|
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
|
|
public int size() {
|
|
return this.this$0.adjacentNodesMultiset().count(this.val$node);
|
|
}
|
|
};
|
|
}
|
|
|
|
@Override // com.google.common.graph.AbstractUndirectedNetworkConnections, com.google.common.graph.NetworkConnections
|
|
public final N removeInEdge(E e, boolean z) {
|
|
if (z) {
|
|
return null;
|
|
}
|
|
return removeOutEdge(e);
|
|
}
|
|
|
|
@Override // com.google.common.graph.AbstractUndirectedNetworkConnections, com.google.common.graph.NetworkConnections
|
|
public final N removeOutEdge(E e) {
|
|
N n = (N) super.removeOutEdge(e);
|
|
Multiset multiset = (Multiset) getReference(this.adjacentNodesReference);
|
|
if (multiset != null) {
|
|
Preconditions.checkState(multiset.remove(n));
|
|
}
|
|
return n;
|
|
}
|
|
|
|
@Override // com.google.common.graph.AbstractUndirectedNetworkConnections, com.google.common.graph.NetworkConnections
|
|
public final void addInEdge(E e, N n, boolean z) {
|
|
if (z) {
|
|
return;
|
|
}
|
|
addOutEdge(e, n);
|
|
}
|
|
|
|
@Override // com.google.common.graph.AbstractUndirectedNetworkConnections, com.google.common.graph.NetworkConnections
|
|
public final void addOutEdge(E e, N n) {
|
|
super.addOutEdge(e, n);
|
|
Multiset multiset = (Multiset) getReference(this.adjacentNodesReference);
|
|
if (multiset != null) {
|
|
Preconditions.checkState(multiset.add(n));
|
|
}
|
|
}
|
|
|
|
private static <T> T getReference(Reference<T> reference) {
|
|
if (reference == null) {
|
|
return null;
|
|
}
|
|
return reference.get();
|
|
}
|
|
}
|