what-the-bank/sources/com/google/common/util/concurrent/AbstractTransformFuture.java

171 lines
7.6 KiB
Java

package com.google.common.util.concurrent;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.FluentFuture;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public abstract class AbstractTransformFuture<I, O, F, T> extends FluentFuture.TrustedFuture<O> implements Runnable {
F function;
ListenableFuture<? extends I> inputFuture;
abstract T doTransform(F f, I i) throws Exception;
abstract void setResult(T t);
/* JADX INFO: Access modifiers changed from: package-private */
public static <I, O> ListenableFuture<O> create(ListenableFuture<I> listenableFuture, AsyncFunction<? super I, ? extends O> asyncFunction, Executor executor) {
Preconditions.checkNotNull(executor);
AsyncTransformFuture asyncTransformFuture = new AsyncTransformFuture(listenableFuture, asyncFunction);
listenableFuture.addListener(asyncTransformFuture, MoreExecutors.rejectionPropagatingExecutor(executor, asyncTransformFuture));
return asyncTransformFuture;
}
/* JADX INFO: Access modifiers changed from: package-private */
public static <I, O> ListenableFuture<O> create(ListenableFuture<I> listenableFuture, Function<? super I, ? extends O> function, Executor executor) {
Preconditions.checkNotNull(function);
TransformFuture transformFuture = new TransformFuture(listenableFuture, function);
listenableFuture.addListener(transformFuture, MoreExecutors.rejectionPropagatingExecutor(executor, transformFuture));
return transformFuture;
}
AbstractTransformFuture(ListenableFuture<? extends I> listenableFuture, F f) {
this.inputFuture = (ListenableFuture) Preconditions.checkNotNull(listenableFuture);
this.function = (F) Preconditions.checkNotNull(f);
}
/* JADX WARN: Multi-variable type inference failed */
@Override // java.lang.Runnable
public final void run() {
ListenableFuture<? extends I> listenableFuture = this.inputFuture;
F f = this.function;
if ((isCancelled() | (listenableFuture == null)) || (f == null)) {
return;
}
this.inputFuture = null;
if (listenableFuture.isCancelled()) {
setFuture(listenableFuture);
return;
}
try {
try {
Object doTransform = doTransform(f, Futures.getDone(listenableFuture));
this.function = null;
setResult(doTransform);
} catch (Throwable th) {
try {
setException(th);
} finally {
this.function = null;
}
}
} catch (Error e) {
setException(e);
} catch (CancellationException unused) {
cancel(false);
} catch (RuntimeException e2) {
setException(e2);
} catch (ExecutionException e3) {
setException(e3.getCause());
}
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.util.concurrent.AbstractFuture
public final void afterDone() {
maybePropagateCancellationTo(this.inputFuture);
this.inputFuture = null;
this.function = null;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.util.concurrent.AbstractFuture
public String pendingToString() {
String str;
ListenableFuture<? extends I> listenableFuture = this.inputFuture;
F f = this.function;
String pendingToString = super.pendingToString();
if (listenableFuture != null) {
String valueOf = String.valueOf(listenableFuture);
StringBuilder sb = new StringBuilder(String.valueOf(valueOf).length() + 16);
sb.append("inputFuture=[");
sb.append(valueOf);
sb.append("], ");
str = sb.toString();
} else {
str = "";
}
if (f == null) {
if (pendingToString == null) {
return null;
}
String valueOf2 = String.valueOf(str);
String valueOf3 = String.valueOf(pendingToString);
return valueOf3.length() != 0 ? valueOf2.concat(valueOf3) : new String(valueOf2);
}
String valueOf4 = String.valueOf(f);
StringBuilder sb2 = new StringBuilder(String.valueOf(str).length() + 11 + String.valueOf(valueOf4).length());
sb2.append(str);
sb2.append("function=[");
sb2.append(valueOf4);
sb2.append("]");
return sb2.toString();
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class AsyncTransformFuture<I, O> extends AbstractTransformFuture<I, O, AsyncFunction<? super I, ? extends O>, ListenableFuture<? extends O>> {
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.util.concurrent.AbstractTransformFuture
final /* bridge */ /* synthetic */ Object doTransform(Object obj, Object obj2) throws Exception {
return doTransform((AsyncFunction<? super AsyncFunction<? super I, ? extends O>, ? extends O>) obj, (AsyncFunction<? super I, ? extends O>) obj2);
}
AsyncTransformFuture(ListenableFuture<? extends I> listenableFuture, AsyncFunction<? super I, ? extends O> asyncFunction) {
super(listenableFuture, asyncFunction);
}
/* JADX WARN: Multi-variable type inference failed */
final ListenableFuture<? extends O> doTransform(AsyncFunction<? super I, ? extends O> asyncFunction, I i) throws Exception {
ListenableFuture<? extends O> apply = asyncFunction.apply(i);
Preconditions.checkNotNull(apply, "AsyncFunction.apply returned null instead of a Future. Did you mean to return immediateFuture(null)? %s", asyncFunction);
return apply;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.util.concurrent.AbstractTransformFuture
public final void setResult(ListenableFuture<? extends O> listenableFuture) {
setFuture(listenableFuture);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class TransformFuture<I, O> extends AbstractTransformFuture<I, O, Function<? super I, ? extends O>, O> {
/* JADX WARN: Multi-variable type inference failed */
@Override // com.google.common.util.concurrent.AbstractTransformFuture
final /* bridge */ /* synthetic */ Object doTransform(Object obj, Object obj2) throws Exception {
return doTransform((Function<? super Function<? super I, ? extends O>, ? extends O>) obj, (Function<? super I, ? extends O>) obj2);
}
TransformFuture(ListenableFuture<? extends I> listenableFuture, Function<? super I, ? extends O> function) {
super(listenableFuture, function);
}
/* JADX WARN: Multi-variable type inference failed */
final O doTransform(Function<? super I, ? extends O> function, I i) {
return function.apply(i);
}
@Override // com.google.common.util.concurrent.AbstractTransformFuture
final void setResult(O o2) {
set(o2);
}
}
}