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 extends FluentFuture.TrustedFuture implements Runnable { F function; ListenableFuture 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 ListenableFuture create(ListenableFuture listenableFuture, AsyncFunction 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 ListenableFuture create(ListenableFuture listenableFuture, Function function, Executor executor) { Preconditions.checkNotNull(function); TransformFuture transformFuture = new TransformFuture(listenableFuture, function); listenableFuture.addListener(transformFuture, MoreExecutors.rejectionPropagatingExecutor(executor, transformFuture)); return transformFuture; } AbstractTransformFuture(ListenableFuture 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 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 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 extends AbstractTransformFuture, ListenableFuture> { /* 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, ? extends O>) obj, (AsyncFunction) obj2); } AsyncTransformFuture(ListenableFuture listenableFuture, AsyncFunction asyncFunction) { super(listenableFuture, asyncFunction); } /* JADX WARN: Multi-variable type inference failed */ final ListenableFuture doTransform(AsyncFunction asyncFunction, I i) throws Exception { ListenableFuture 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 listenableFuture) { setFuture(listenableFuture); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes2.dex */ public static final class TransformFuture extends AbstractTransformFuture, 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, ? extends O>) obj, (Function) obj2); } TransformFuture(ListenableFuture listenableFuture, Function function) { super(listenableFuture, function); } /* JADX WARN: Multi-variable type inference failed */ final O doTransform(Function function, I i) { return function.apply(i); } @Override // com.google.common.util.concurrent.AbstractTransformFuture final void setResult(O o2) { set(o2); } } }