what-the-bank/sources/com/google/common/collect/Interners.java

111 lines
3.2 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.collect;
import com.google.common.base.Equivalence;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.collect.MapMaker;
/* loaded from: classes2.dex */
public final class Interners {
private Interners() {
}
/* loaded from: classes2.dex */
public static class InternerBuilder {
private final MapMaker mapMaker;
private boolean strong;
private InternerBuilder() {
this.mapMaker = new MapMaker();
this.strong = true;
}
public InternerBuilder concurrencyLevel(int i) {
this.mapMaker.concurrencyLevel(i);
return this;
}
public <E> Interner<E> build() {
if (!this.strong) {
this.mapMaker.weakKeys();
}
return new InternerImpl(this.mapMaker);
}
public InternerBuilder weak() {
this.strong = false;
return this;
}
public InternerBuilder strong() {
this.strong = true;
return this;
}
}
public static InternerBuilder newBuilder() {
return new InternerBuilder();
}
public static <E> Interner<E> newStrongInterner() {
return newBuilder().strong().build();
}
public static <E> Interner<E> newWeakInterner() {
return newBuilder().weak().build();
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class InternerImpl<E> implements Interner<E> {
final MapMakerInternalMap<E, MapMaker.Dummy, ?, ?> map;
private InternerImpl(MapMaker mapMaker) {
this.map = MapMakerInternalMap.createWithDummyValues(mapMaker.keyEquivalence(Equivalence.equals()));
}
/* JADX WARN: Type inference failed for: r0v1, types: [com.google.common.collect.MapMakerInternalMap$InternalEntry] */
@Override // com.google.common.collect.Interner
public final E intern(E e) {
E e2;
do {
?? entry = this.map.getEntry(e);
if (entry != 0 && (e2 = (E) entry.getKey()) != null) {
return e2;
}
} while (this.map.putIfAbsent(e, MapMaker.Dummy.VALUE) != null);
return e;
}
}
public static <E> Function<E, E> asFunction(Interner<E> interner) {
return new InternerFunction((Interner) Preconditions.checkNotNull(interner));
}
/* loaded from: classes2.dex */
static class InternerFunction<E> implements Function<E, E> {
private final Interner<E> interner;
public InternerFunction(Interner<E> interner) {
this.interner = interner;
}
@Override // com.google.common.base.Function
public E apply(E e) {
return this.interner.intern(e);
}
public int hashCode() {
return this.interner.hashCode();
}
@Override // com.google.common.base.Function
public boolean equals(Object obj) {
if (obj instanceof InternerFunction) {
return this.interner.equals(((InternerFunction) obj).interner);
}
return false;
}
}
}