package com.google.common.base; import com.airbnb.deeplinkdispatch.UrlTreeKt; import java.io.Serializable; import java.util.concurrent.TimeUnit; /* loaded from: classes2.dex */ public final class Suppliers { /* loaded from: classes2.dex */ interface SupplierFunction extends Function, T> { } private Suppliers() { } public static Supplier compose(Function function, Supplier supplier) { return new SupplierComposition(function, supplier); } /* loaded from: classes2.dex */ static class SupplierComposition implements Supplier, Serializable { private static final long serialVersionUID = 0; final Function function; final Supplier supplier; SupplierComposition(Function function, Supplier supplier) { this.function = (Function) Preconditions.checkNotNull(function); this.supplier = (Supplier) Preconditions.checkNotNull(supplier); } @Override // com.google.common.base.Supplier public T get() { return this.function.apply(this.supplier.get()); } public boolean equals(Object obj) { if (!(obj instanceof SupplierComposition)) { return false; } SupplierComposition supplierComposition = (SupplierComposition) obj; return this.function.equals(supplierComposition.function) && this.supplier.equals(supplierComposition.supplier); } public int hashCode() { return Objects.hashCode(this.function, this.supplier); } public String toString() { String valueOf = String.valueOf(this.function); String valueOf2 = String.valueOf(this.supplier); StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 21 + String.valueOf(valueOf2).length()); sb.append("Suppliers.compose("); sb.append(valueOf); sb.append(", "); sb.append(valueOf2); sb.append(")"); return sb.toString(); } } public static Supplier memoize(Supplier supplier) { if ((supplier instanceof NonSerializableMemoizingSupplier) || (supplier instanceof MemoizingSupplier)) { return supplier; } if (supplier instanceof Serializable) { return new MemoizingSupplier(supplier); } return new NonSerializableMemoizingSupplier(supplier); } /* loaded from: classes2.dex */ static class MemoizingSupplier implements Supplier, Serializable { private static final long serialVersionUID = 0; final Supplier delegate; volatile transient boolean initialized; transient T value; MemoizingSupplier(Supplier supplier) { this.delegate = (Supplier) Preconditions.checkNotNull(supplier); } @Override // com.google.common.base.Supplier public T get() { if (!this.initialized) { synchronized (this) { if (!this.initialized) { T t = this.delegate.get(); this.value = t; this.initialized = true; return t; } } } return this.value; } public String toString() { Object obj; if (this.initialized) { String valueOf = String.valueOf(this.value); StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 25); sb.append(" implements Supplier { volatile Supplier delegate; volatile boolean initialized; T value; NonSerializableMemoizingSupplier(Supplier supplier) { this.delegate = (Supplier) Preconditions.checkNotNull(supplier); } @Override // com.google.common.base.Supplier public T get() { if (!this.initialized) { synchronized (this) { if (!this.initialized) { T t = this.delegate.get(); this.value = t; this.initialized = true; this.delegate = null; return t; } } } return this.value; } public String toString() { Object obj = this.delegate; if (obj == null) { String valueOf = String.valueOf(this.value); StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 25); sb.append(" Supplier memoizeWithExpiration(Supplier supplier, long j, TimeUnit timeUnit) { return new ExpiringMemoizingSupplier(supplier, j, timeUnit); } /* loaded from: classes2.dex */ static class ExpiringMemoizingSupplier implements Supplier, Serializable { private static final long serialVersionUID = 0; final Supplier delegate; final long durationNanos; volatile transient long expirationNanos; volatile transient T value; ExpiringMemoizingSupplier(Supplier supplier, long j, TimeUnit timeUnit) { this.delegate = (Supplier) Preconditions.checkNotNull(supplier); this.durationNanos = timeUnit.toNanos(j); Preconditions.checkArgument(j > 0, "duration (%s %s) must be > 0", j, timeUnit); } @Override // com.google.common.base.Supplier public T get() { long j = this.expirationNanos; long systemNanoTime = Platform.systemNanoTime(); if (j == 0 || systemNanoTime - j >= 0) { synchronized (this) { if (j == this.expirationNanos) { T t = this.delegate.get(); this.value = t; long j2 = systemNanoTime + this.durationNanos; if (j2 == 0) { j2 = 1; } this.expirationNanos = j2; return t; } } } return this.value; } public String toString() { String valueOf = String.valueOf(this.delegate); long j = this.durationNanos; StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 62); sb.append("Suppliers.memoizeWithExpiration("); sb.append(valueOf); sb.append(", "); sb.append(j); sb.append(", NANOS)"); return sb.toString(); } } public static Supplier ofInstance(T t) { return new SupplierOfInstance(t); } /* loaded from: classes2.dex */ static class SupplierOfInstance implements Supplier, Serializable { private static final long serialVersionUID = 0; final T instance; SupplierOfInstance(T t) { this.instance = t; } public boolean equals(Object obj) { if (obj instanceof SupplierOfInstance) { return Objects.equal(this.instance, ((SupplierOfInstance) obj).instance); } return false; } public int hashCode() { return Objects.hashCode(this.instance); } public String toString() { String valueOf = String.valueOf(this.instance); StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 22); sb.append("Suppliers.ofInstance("); sb.append(valueOf); sb.append(")"); return sb.toString(); } @Override // com.google.common.base.Supplier public T get() { return this.instance; } } public static Supplier synchronizedSupplier(Supplier supplier) { return new ThreadSafeSupplier(supplier); } /* loaded from: classes2.dex */ static class ThreadSafeSupplier implements Supplier, Serializable { private static final long serialVersionUID = 0; final Supplier delegate; ThreadSafeSupplier(Supplier supplier) { this.delegate = (Supplier) Preconditions.checkNotNull(supplier); } @Override // com.google.common.base.Supplier public T get() { T t; synchronized (this.delegate) { t = this.delegate.get(); } return t; } public String toString() { String valueOf = String.valueOf(this.delegate); StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 32); sb.append("Suppliers.synchronizedSupplier("); sb.append(valueOf); sb.append(")"); return sb.toString(); } } public static Function, T> supplierFunction() { return SupplierFunctionImpl.INSTANCE; } /* loaded from: classes2.dex */ enum SupplierFunctionImpl implements SupplierFunction { INSTANCE; @Override // com.google.common.base.Function public final Object apply(Supplier supplier) { return supplier.get(); } @Override // java.lang.Enum public final String toString() { return "Suppliers.supplierFunction()"; } } }