mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-14 09:57:16 +01:00
112 lines
3.5 KiB
Java
112 lines
3.5 KiB
Java
package com.google.common.graph;
|
|
|
|
import com.google.common.annotations.Beta;
|
|
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 com.google.errorprone.annotations.Immutable;
|
|
import java.util.Comparator;
|
|
import java.util.Map;
|
|
import okio.Buffer$$ExternalSyntheticBUOutline0;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@Immutable
|
|
@Beta
|
|
/* loaded from: classes8.dex */
|
|
public final class ElementOrder<T> {
|
|
private final Comparator<T> comparator;
|
|
private final Type type;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public enum Type {
|
|
UNORDERED,
|
|
STABLE,
|
|
INSERTION,
|
|
SORTED
|
|
}
|
|
|
|
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> 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 static <S> ElementOrder<S> stable() {
|
|
return new ElementOrder<>(Type.STABLE, null);
|
|
}
|
|
|
|
public static <S> ElementOrder<S> unordered() {
|
|
return new ElementOrder<>(Type.UNORDERED, null);
|
|
}
|
|
|
|
public Comparator<T> comparator() {
|
|
Comparator<T> comparator = this.comparator;
|
|
if (comparator != null) {
|
|
return comparator;
|
|
}
|
|
Buffer$$ExternalSyntheticBUOutline0.m$1("This ordering does not define a comparator.");
|
|
return null;
|
|
}
|
|
|
|
public <K extends T, V> Map<K, V> createMap(int i) {
|
|
int ordinal = this.type.ordinal();
|
|
if (ordinal == 0) {
|
|
return Maps.newHashMapWithExpectedSize(i);
|
|
}
|
|
if (ordinal == 1 || ordinal == 2) {
|
|
return Maps.newLinkedHashMapWithExpectedSize(i);
|
|
}
|
|
if (ordinal == 3) {
|
|
return Maps.newTreeMap(comparator());
|
|
}
|
|
Buffer$$ExternalSyntheticBUOutline0.m$2();
|
|
return null;
|
|
}
|
|
|
|
public 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 int hashCode() {
|
|
return Objects.hashCode(this.type, this.comparator);
|
|
}
|
|
|
|
public 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();
|
|
}
|
|
|
|
public Type type() {
|
|
return this.type;
|
|
}
|
|
|
|
/* JADX WARN: Multi-variable type inference failed */
|
|
public <T1 extends T> ElementOrder<T1> cast() {
|
|
return this;
|
|
}
|
|
}
|