mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-18 03:47:18 +01:00
335 lines
13 KiB
Java
335 lines
13 KiB
Java
package com.google.common.base;
|
|
|
|
import androidx.biometric.ErrorUtils$$ExternalSyntheticOutline0;
|
|
import com.amazon.alexa.ra.core.ui.markdown.parser.formatter.MarkdownConstants;
|
|
import com.google.common.annotations.GwtCompatible;
|
|
import com.google.common.annotations.GwtIncompatible;
|
|
import com.google.common.annotations.J2ktIncompatible;
|
|
import com.google.common.annotations.VisibleForTesting;
|
|
import defpackage.a$$ExternalSyntheticOutline0;
|
|
import java.io.IOException;
|
|
import java.io.ObjectInputStream;
|
|
import java.io.Serializable;
|
|
import java.time.Duration;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@GwtCompatible(emulated = true)
|
|
/* loaded from: classes8.dex */
|
|
public final class Suppliers {
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@VisibleForTesting
|
|
public static class ExpiringMemoizingSupplier<T> implements Supplier<T>, Serializable {
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
private static final long serialVersionUID = 0;
|
|
final Supplier<T> delegate;
|
|
final long durationNanos;
|
|
volatile transient long expirationNanos;
|
|
private transient Object lock = new Object();
|
|
volatile transient T value;
|
|
|
|
public ExpiringMemoizingSupplier(Supplier<T> supplier, long j) {
|
|
this.delegate = supplier;
|
|
this.durationNanos = j;
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
|
objectInputStream.defaultReadObject();
|
|
this.lock = new Object();
|
|
}
|
|
|
|
@Override // com.google.common.base.Supplier
|
|
@ParametricNullness
|
|
public T get() {
|
|
long j = this.expirationNanos;
|
|
long nanoTime = System.nanoTime();
|
|
if (j == 0 || nanoTime - j >= 0) {
|
|
synchronized (this.lock) {
|
|
try {
|
|
if (j == this.expirationNanos) {
|
|
T t = this.delegate.get();
|
|
this.value = t;
|
|
long j2 = nanoTime + this.durationNanos;
|
|
if (j2 == 0) {
|
|
j2 = 1;
|
|
}
|
|
this.expirationNanos = j2;
|
|
return t;
|
|
}
|
|
} catch (Throwable th) {
|
|
throw th;
|
|
}
|
|
}
|
|
}
|
|
return (T) NullnessCasts.uncheckedCastNullableTToT(this.value);
|
|
}
|
|
|
|
public String toString() {
|
|
StringBuilder sb = new StringBuilder("Suppliers.memoizeWithExpiration(");
|
|
sb.append(this.delegate);
|
|
sb.append(", ");
|
|
return a$$ExternalSyntheticOutline0.m(this.durationNanos, ", NANOS)", sb);
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@VisibleForTesting
|
|
public static class MemoizingSupplier<T> implements Supplier<T>, Serializable {
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
private static final long serialVersionUID = 0;
|
|
final Supplier<T> delegate;
|
|
volatile transient boolean initialized;
|
|
private transient Object lock = new Object();
|
|
transient T value;
|
|
|
|
public MemoizingSupplier(Supplier<T> supplier) {
|
|
this.delegate = (Supplier) Preconditions.checkNotNull(supplier);
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
|
|
objectInputStream.defaultReadObject();
|
|
this.lock = new Object();
|
|
}
|
|
|
|
@Override // com.google.common.base.Supplier
|
|
@ParametricNullness
|
|
public T get() {
|
|
if (!this.initialized) {
|
|
synchronized (this.lock) {
|
|
try {
|
|
if (!this.initialized) {
|
|
T t = this.delegate.get();
|
|
this.value = t;
|
|
this.initialized = true;
|
|
return t;
|
|
}
|
|
} finally {
|
|
}
|
|
}
|
|
}
|
|
return (T) NullnessCasts.uncheckedCastNullableTToT(this.value);
|
|
}
|
|
|
|
public String toString() {
|
|
return ErrorUtils$$ExternalSyntheticOutline0.m(new StringBuilder("Suppliers.memoize("), MarkdownConstants.RIGHT_PARENTHESIS, this.initialized ? ErrorUtils$$ExternalSyntheticOutline0.m(new StringBuilder("<supplier that returned "), ">", this.value) : this.delegate);
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@VisibleForTesting
|
|
public static class NonSerializableMemoizingSupplier<T> implements Supplier<T> {
|
|
private static final Supplier<Void> SUCCESSFULLY_COMPUTED = new Suppliers$NonSerializableMemoizingSupplier$$ExternalSyntheticLambda0();
|
|
private volatile Supplier<T> delegate;
|
|
private final Object lock = new Object();
|
|
private T value;
|
|
|
|
public NonSerializableMemoizingSupplier(Supplier<T> supplier) {
|
|
this.delegate = (Supplier) Preconditions.checkNotNull(supplier);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public static /* synthetic */ Void lambda$static$0() {
|
|
throw new IllegalStateException();
|
|
}
|
|
|
|
@Override // com.google.common.base.Supplier
|
|
@ParametricNullness
|
|
public T get() {
|
|
Supplier<T> supplier = this.delegate;
|
|
Supplier<T> supplier2 = (Supplier<T>) SUCCESSFULLY_COMPUTED;
|
|
if (supplier != supplier2) {
|
|
synchronized (this.lock) {
|
|
try {
|
|
if (this.delegate != supplier2) {
|
|
T t = this.delegate.get();
|
|
this.value = t;
|
|
this.delegate = supplier2;
|
|
return t;
|
|
}
|
|
} finally {
|
|
}
|
|
}
|
|
}
|
|
return (T) NullnessCasts.uncheckedCastNullableTToT(this.value);
|
|
}
|
|
|
|
public String toString() {
|
|
Object obj = this.delegate;
|
|
StringBuilder sb = new StringBuilder("Suppliers.memoize(");
|
|
if (obj == SUCCESSFULLY_COMPUTED) {
|
|
obj = ErrorUtils$$ExternalSyntheticOutline0.m(new StringBuilder("<supplier that returned "), ">", this.value);
|
|
}
|
|
return ErrorUtils$$ExternalSyntheticOutline0.m(sb, MarkdownConstants.RIGHT_PARENTHESIS, obj);
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public static class SupplierComposition<F, T> implements Supplier<T>, Serializable {
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
private static final long serialVersionUID = 0;
|
|
final Function<? super F, T> function;
|
|
final Supplier<F> supplier;
|
|
|
|
public SupplierComposition(Function<? super F, T> function, Supplier<F> supplier) {
|
|
this.function = (Function) Preconditions.checkNotNull(function);
|
|
this.supplier = (Supplier) Preconditions.checkNotNull(supplier);
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (obj instanceof SupplierComposition) {
|
|
SupplierComposition supplierComposition = (SupplierComposition) obj;
|
|
if (this.function.equals(supplierComposition.function) && this.supplier.equals(supplierComposition.supplier)) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // com.google.common.base.Supplier
|
|
@ParametricNullness
|
|
public T get() {
|
|
return this.function.apply(this.supplier.get());
|
|
}
|
|
|
|
public int hashCode() {
|
|
return Objects.hashCode(this.function, this.supplier);
|
|
}
|
|
|
|
public String toString() {
|
|
return "Suppliers.compose(" + this.function + ", " + this.supplier + MarkdownConstants.RIGHT_PARENTHESIS;
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public interface SupplierFunction<T> extends Function<Supplier<T>, T> {
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public static class SupplierOfInstance<T> implements Supplier<T>, Serializable {
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
private static final long serialVersionUID = 0;
|
|
|
|
@ParametricNullness
|
|
final T instance;
|
|
|
|
public SupplierOfInstance(@ParametricNullness T t) {
|
|
this.instance = t;
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (obj instanceof SupplierOfInstance) {
|
|
return Objects.equal(this.instance, ((SupplierOfInstance) obj).instance);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // com.google.common.base.Supplier
|
|
@ParametricNullness
|
|
public T get() {
|
|
return this.instance;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return Objects.hashCode(this.instance);
|
|
}
|
|
|
|
public String toString() {
|
|
return ErrorUtils$$ExternalSyntheticOutline0.m(new StringBuilder("Suppliers.ofInstance("), MarkdownConstants.RIGHT_PARENTHESIS, this.instance);
|
|
}
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@J2ktIncompatible
|
|
public static class ThreadSafeSupplier<T> implements Supplier<T>, Serializable {
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
private static final long serialVersionUID = 0;
|
|
final Supplier<T> delegate;
|
|
|
|
public ThreadSafeSupplier(Supplier<T> supplier) {
|
|
this.delegate = (Supplier) Preconditions.checkNotNull(supplier);
|
|
}
|
|
|
|
@Override // com.google.common.base.Supplier
|
|
@ParametricNullness
|
|
public T get() {
|
|
T t;
|
|
synchronized (this.delegate) {
|
|
t = this.delegate.get();
|
|
}
|
|
return t;
|
|
}
|
|
|
|
public String toString() {
|
|
return "Suppliers.synchronizedSupplier(" + this.delegate + MarkdownConstants.RIGHT_PARENTHESIS;
|
|
}
|
|
}
|
|
|
|
private Suppliers() {
|
|
}
|
|
|
|
public static <F, T> Supplier<T> compose(Function<? super F, T> function, Supplier<F> supplier) {
|
|
return new SupplierComposition(function, supplier);
|
|
}
|
|
|
|
public static <T> Supplier<T> memoize(Supplier<T> supplier) {
|
|
return !(supplier instanceof NonSerializableMemoizingSupplier) ? supplier instanceof MemoizingSupplier ? supplier : supplier instanceof Serializable ? new MemoizingSupplier(supplier) : new NonSerializableMemoizingSupplier(supplier) : supplier;
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
@GwtIncompatible
|
|
@IgnoreJRERequirement
|
|
public static <T> Supplier<T> memoizeWithExpiration(Supplier<T> supplier, Duration duration) {
|
|
Preconditions.checkNotNull(supplier);
|
|
Preconditions.checkArgument((duration.isNegative() || duration.isZero()) ? false : true, "duration (%s) must be > 0", duration);
|
|
return new ExpiringMemoizingSupplier(supplier, Internal.toNanosSaturated(duration));
|
|
}
|
|
|
|
public static <T> Supplier<T> ofInstance(@ParametricNullness T t) {
|
|
return new SupplierOfInstance(t);
|
|
}
|
|
|
|
public static <T> Function<Supplier<T>, T> supplierFunction() {
|
|
return SupplierFunctionImpl.INSTANCE;
|
|
}
|
|
|
|
@J2ktIncompatible
|
|
public static <T> Supplier<T> synchronizedSupplier(Supplier<T> supplier) {
|
|
return new ThreadSafeSupplier(supplier);
|
|
}
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
public enum SupplierFunctionImpl implements SupplierFunction<Object> {
|
|
INSTANCE;
|
|
|
|
@Override // java.lang.Enum
|
|
public String toString() {
|
|
return "Suppliers.supplierFunction()";
|
|
}
|
|
|
|
@Override // com.google.common.base.Function
|
|
public Object apply(Supplier<Object> supplier) {
|
|
return supplier.get();
|
|
}
|
|
}
|
|
|
|
public static <T> Supplier<T> memoizeWithExpiration(Supplier<T> supplier, long j, TimeUnit timeUnit) {
|
|
Preconditions.checkNotNull(supplier);
|
|
Preconditions.checkArgument(j > 0, "duration (%s %s) must be > 0", j, timeUnit);
|
|
return new ExpiringMemoizingSupplier(supplier, timeUnit.toNanos(j));
|
|
}
|
|
}
|