what-the-bank/sources/com/google/common/cache/CacheLoader.java

131 lines
4.8 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package com.google.common.cache;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListenableFutureTask;
import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.Executor;
/* loaded from: classes2.dex */
public abstract class CacheLoader<K, V> {
public abstract V load(K k) throws Exception;
public ListenableFuture<V> reload(K k, V v) throws Exception {
Preconditions.checkNotNull(k);
Preconditions.checkNotNull(v);
return Futures.immediateFuture(load(k));
}
public Map<K, V> loadAll(Iterable<? extends K> iterable) throws Exception {
throw new UnsupportedLoadingOperationException();
}
public static <K, V> CacheLoader<K, V> from(Function<K, V> function) {
return new FunctionToCacheLoader(function);
}
public static <V> CacheLoader<Object, V> from(Supplier<V> supplier) {
return new SupplierToCacheLoader(supplier);
}
/* loaded from: classes2.dex */
static final class FunctionToCacheLoader<K, V> extends CacheLoader<K, V> implements Serializable {
private static final long serialVersionUID = 0;
private final Function<K, V> computingFunction;
public FunctionToCacheLoader(Function<K, V> function) {
this.computingFunction = (Function) Preconditions.checkNotNull(function);
}
@Override // com.google.common.cache.CacheLoader
public final V load(K k) {
return (V) this.computingFunction.apply(Preconditions.checkNotNull(k));
}
}
public static <K, V> CacheLoader<K, V> asyncReloading(CacheLoader<K, V> cacheLoader, Executor executor) {
Preconditions.checkNotNull(cacheLoader);
Preconditions.checkNotNull(executor);
return new AnonymousClass1(cacheLoader, executor);
}
/* renamed from: com.google.common.cache.CacheLoader$1, reason: invalid class name */
/* loaded from: classes2.dex */
class AnonymousClass1 extends CacheLoader<K, V> {
final Executor val$executor;
final CacheLoader val$loader;
AnonymousClass1(CacheLoader cacheLoader, Executor executor) {
this.val$loader = cacheLoader;
this.val$executor = executor;
}
@Override // com.google.common.cache.CacheLoader
public V load(K k) throws Exception {
return (V) this.val$loader.load(k);
}
@Override // com.google.common.cache.CacheLoader
public ListenableFuture<V> reload(K k, V v) throws Exception {
ListenableFutureTask create = ListenableFutureTask.create(new Callable<V>(this, k, v) { // from class: com.google.common.cache.CacheLoader.1.1
final AnonymousClass1 this$0;
final Object val$key;
final Object val$oldValue;
{
this.this$0 = this;
this.val$key = k;
this.val$oldValue = v;
}
/* JADX WARN: Multi-variable type inference failed */
@Override // java.util.concurrent.Callable
public V call() throws Exception {
return this.this$0.val$loader.reload(this.val$key, this.val$oldValue).get();
}
});
this.val$executor.execute(create);
return create;
}
@Override // com.google.common.cache.CacheLoader
public Map<K, V> loadAll(Iterable<? extends K> iterable) throws Exception {
return this.val$loader.loadAll(iterable);
}
}
/* loaded from: classes2.dex */
static final class SupplierToCacheLoader<V> extends CacheLoader<Object, V> implements Serializable {
private static final long serialVersionUID = 0;
private final Supplier<V> computingSupplier;
public SupplierToCacheLoader(Supplier<V> supplier) {
this.computingSupplier = (Supplier) Preconditions.checkNotNull(supplier);
}
@Override // com.google.common.cache.CacheLoader
public final V load(Object obj) {
Preconditions.checkNotNull(obj);
return this.computingSupplier.get();
}
}
/* loaded from: classes2.dex */
public static final class UnsupportedLoadingOperationException extends UnsupportedOperationException {
UnsupportedLoadingOperationException() {
}
}
/* loaded from: classes2.dex */
public static final class InvalidCacheLoadException extends RuntimeException {
public InvalidCacheLoadException(String str) {
super(str);
}
}
}