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

201 lines
6.9 KiB
Java

package com.google.common.graph;
import com.airbnb.deeplinkdispatch.UrlTreeKt;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Iterators;
import com.google.common.collect.UnmodifiableIterator;
import java.util.Iterator;
/* loaded from: classes2.dex */
public abstract class EndpointPair<N> implements Iterable<N> {
private final N nodeU;
private final N nodeV;
public abstract boolean equals(Object obj);
public abstract int hashCode();
public abstract boolean isOrdered();
public abstract N source();
public abstract N target();
private EndpointPair(N n, N n2) {
this.nodeU = (N) Preconditions.checkNotNull(n);
this.nodeV = (N) Preconditions.checkNotNull(n2);
}
public static <N> EndpointPair<N> ordered(N n, N n2) {
return new Ordered(n, n2);
}
public static <N> EndpointPair<N> unordered(N n, N n2) {
return new Unordered(n2, n);
}
/* JADX INFO: Access modifiers changed from: package-private */
public static <N> EndpointPair<N> of(Graph<?> graph, N n, N n2) {
return graph.isDirected() ? ordered(n, n2) : unordered(n, n2);
}
/* JADX INFO: Access modifiers changed from: package-private */
public static <N> EndpointPair<N> of(Network<?, ?> network, N n, N n2) {
return network.isDirected() ? ordered(n, n2) : unordered(n, n2);
}
public final N adjacentNode(Object obj) {
if (obj.equals(this.nodeU)) {
return this.nodeV;
}
if (obj.equals(this.nodeV)) {
return this.nodeU;
}
String valueOf = String.valueOf(this);
String valueOf2 = String.valueOf(obj);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 36 + String.valueOf(valueOf2).length());
sb.append("EndpointPair ");
sb.append(valueOf);
sb.append(" does not contain node ");
sb.append(valueOf2);
throw new IllegalArgumentException(sb.toString());
}
@Override // java.lang.Iterable
public final UnmodifiableIterator<N> iterator() {
return Iterators.forArray(this.nodeU, this.nodeV);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class Ordered<N> extends EndpointPair<N> {
@Override // com.google.common.graph.EndpointPair
public final boolean isOrdered() {
return true;
}
@Override // com.google.common.graph.EndpointPair, java.lang.Iterable
public final /* bridge */ /* synthetic */ Iterator iterator() {
return super.iterator();
}
private Ordered(N n, N n2) {
super(n, n2);
}
@Override // com.google.common.graph.EndpointPair
public final N source() {
return nodeU();
}
@Override // com.google.common.graph.EndpointPair
public final N target() {
return nodeV();
}
@Override // com.google.common.graph.EndpointPair
public final boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof EndpointPair)) {
return false;
}
EndpointPair endpointPair = (EndpointPair) obj;
if (isOrdered() != endpointPair.isOrdered()) {
return false;
}
return source().equals(endpointPair.source()) && target().equals(endpointPair.target());
}
@Override // com.google.common.graph.EndpointPair
public final int hashCode() {
return Objects.hashCode(source(), target());
}
public final String toString() {
String valueOf = String.valueOf(source());
String valueOf2 = String.valueOf(target());
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 6 + String.valueOf(valueOf2).length());
sb.append(UrlTreeKt.configurablePathSegmentPrefix);
sb.append(valueOf);
sb.append(" -> ");
sb.append(valueOf2);
sb.append(UrlTreeKt.configurablePathSegmentSuffix);
return sb.toString();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class Unordered<N> extends EndpointPair<N> {
@Override // com.google.common.graph.EndpointPair
public final boolean isOrdered() {
return false;
}
@Override // com.google.common.graph.EndpointPair, java.lang.Iterable
public final /* bridge */ /* synthetic */ Iterator iterator() {
return super.iterator();
}
private Unordered(N n, N n2) {
super(n, n2);
}
@Override // com.google.common.graph.EndpointPair
public final N source() {
throw new UnsupportedOperationException("Cannot call source()/target() on a EndpointPair from an undirected graph. Consider calling adjacentNode(node) if you already have a node, or nodeU()/nodeV() if you don't.");
}
@Override // com.google.common.graph.EndpointPair
public final N target() {
throw new UnsupportedOperationException("Cannot call source()/target() on a EndpointPair from an undirected graph. Consider calling adjacentNode(node) if you already have a node, or nodeU()/nodeV() if you don't.");
}
@Override // com.google.common.graph.EndpointPair
public final boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof EndpointPair)) {
return false;
}
EndpointPair endpointPair = (EndpointPair) obj;
if (isOrdered() != endpointPair.isOrdered()) {
return false;
}
if (nodeU().equals(endpointPair.nodeU())) {
return nodeV().equals(endpointPair.nodeV());
}
return nodeU().equals(endpointPair.nodeV()) && nodeV().equals(endpointPair.nodeU());
}
@Override // com.google.common.graph.EndpointPair
public final int hashCode() {
return nodeU().hashCode() + nodeV().hashCode();
}
public final String toString() {
String valueOf = String.valueOf(nodeU());
String valueOf2 = String.valueOf(nodeV());
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 4 + String.valueOf(valueOf2).length());
sb.append("[");
sb.append(valueOf);
sb.append(", ");
sb.append(valueOf2);
sb.append("]");
return sb.toString();
}
}
public final N nodeV() {
return this.nodeV;
}
public final N nodeU() {
return this.nodeU;
}
}