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

134 lines
4.4 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.MoreObjects;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import com.google.common.collect.Ordering;
import java.util.Comparator;
import java.util.Map;
/* loaded from: classes2.dex */
public final class ElementOrder<T> {
private final Comparator<T> comparator;
private final Type type;
/* loaded from: classes2.dex */
public enum Type {
UNORDERED,
STABLE,
INSERTION,
SORTED
}
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: Multi-variable type inference failed */
public final <T1 extends T> ElementOrder<T1> cast() {
return this;
}
private ElementOrder(Type type, Comparator<T> comparator) {
this.type = (Type) Preconditions.checkNotNull(type);
this.comparator = comparator;
Preconditions.checkState((type == Type.SORTED) == (comparator != null));
}
public static <S> ElementOrder<S> unordered() {
return new ElementOrder<>(Type.UNORDERED, null);
}
public static <S> ElementOrder<S> stable() {
return new ElementOrder<>(Type.STABLE, null);
}
public static <S> ElementOrder<S> insertion() {
return new ElementOrder<>(Type.INSERTION, null);
}
public static <S extends Comparable<? super S>> ElementOrder<S> natural() {
return new ElementOrder<>(Type.SORTED, Ordering.natural());
}
public static <S> ElementOrder<S> sorted(Comparator<S> comparator) {
return new ElementOrder<>(Type.SORTED, (Comparator) Preconditions.checkNotNull(comparator));
}
public final Comparator<T> comparator() {
Comparator<T> comparator = this.comparator;
if (comparator != null) {
return comparator;
}
throw new UnsupportedOperationException("This ordering does not define a comparator.");
}
public final boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (!(obj instanceof ElementOrder)) {
return false;
}
ElementOrder elementOrder = (ElementOrder) obj;
return this.type == elementOrder.type && Objects.equal(this.comparator, elementOrder.comparator);
}
public final int hashCode() {
return Objects.hashCode(this.type, this.comparator);
}
public final String toString() {
MoreObjects.ToStringHelper add = MoreObjects.toStringHelper(this).add("type", this.type);
Comparator<T> comparator = this.comparator;
if (comparator != null) {
add.add("comparator", comparator);
}
return add.toString();
}
/* renamed from: com.google.common.graph.ElementOrder$1, reason: invalid class name */
/* loaded from: classes2.dex */
static /* synthetic */ class AnonymousClass1 {
static final int[] $SwitchMap$com$google$common$graph$ElementOrder$Type;
static {
int[] iArr = new int[Type.values().length];
$SwitchMap$com$google$common$graph$ElementOrder$Type = iArr;
try {
iArr[Type.UNORDERED.ordinal()] = 1;
} catch (NoSuchFieldError unused) {
}
try {
$SwitchMap$com$google$common$graph$ElementOrder$Type[Type.INSERTION.ordinal()] = 2;
} catch (NoSuchFieldError unused2) {
}
try {
$SwitchMap$com$google$common$graph$ElementOrder$Type[Type.STABLE.ordinal()] = 3;
} catch (NoSuchFieldError unused3) {
}
try {
$SwitchMap$com$google$common$graph$ElementOrder$Type[Type.SORTED.ordinal()] = 4;
} catch (NoSuchFieldError unused4) {
}
}
}
/* JADX INFO: Access modifiers changed from: package-private */
public final <K extends T, V> Map<K, V> createMap(int i) {
int i2 = AnonymousClass1.$SwitchMap$com$google$common$graph$ElementOrder$Type[this.type.ordinal()];
if (i2 == 1) {
return Maps.newHashMapWithExpectedSize(i);
}
if (i2 == 2 || i2 == 3) {
return Maps.newLinkedHashMapWithExpectedSize(i);
}
if (i2 == 4) {
return Maps.newTreeMap(comparator());
}
throw new AssertionError();
}
public final Type type() {
return this.type;
}
}