package csdk.gluads.util; import androidx.annotation.NonNull; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; /* loaded from: classes4.dex */ public class Futures { @NonNull public static Future successful(V v) { return new SuccessfulFuture(v); } @NonNull public static Future failed(Throwable th) { return new FailedFuture(th); } @NonNull public static SettableFuture settable() { return new SettableFuture<>(); } public static class SuccessfulFuture implements Future { public final V value; @Override // java.util.concurrent.Future public boolean cancel(boolean z) { return false; } @Override // java.util.concurrent.Future public V get() throws InterruptedException, ExecutionException { return this.value; } @Override // java.util.concurrent.Future public boolean isCancelled() { return false; } @Override // java.util.concurrent.Future public boolean isDone() { return true; } private SuccessfulFuture(V v) { this.value = v; } @Override // java.util.concurrent.Future public V get(long j, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException { return get(); } } public static class FailedFuture implements Future { public final Throwable failure; @Override // java.util.concurrent.Future public boolean cancel(boolean z) { return false; } @Override // java.util.concurrent.Future public boolean isCancelled() { return false; } @Override // java.util.concurrent.Future public boolean isDone() { return true; } public FailedFuture(Throwable th) { this.failure = th; } @Override // java.util.concurrent.Future public V get() throws InterruptedException, ExecutionException { throw new ExecutionException(this.failure); } @Override // java.util.concurrent.Future public V get(long j, TimeUnit timeUnit) throws InterruptedException, ExecutionException, TimeoutException { return get(); } } public static class SettableFuture implements Future { private static final int DONE_RES_CANCELLED = 3; private static final int DONE_RES_COMPLETED = 1; private static final int DONE_RES_FAILED = 2; private static final int DONE_RES_INITIAL = 0; private volatile int doneRes; private volatile Object result; @Override // java.util.concurrent.Future public boolean isCancelled() { return false; } @Override // java.util.concurrent.Future public boolean isDone() { return this.doneRes != 0; } @Override // java.util.concurrent.Future public V get() { throw new UnsupportedOperationException("Blocking get is not supported."); } @Override // java.util.concurrent.Future public V get(long j, TimeUnit timeUnit) throws ExecutionException, TimeoutException { if (j > 0) { throw new UnsupportedOperationException("Blocking get() is not supported."); } if (!isDone()) { throw new TimeoutException(); } if (this.doneRes == 3) { throw new CancellationException(); } if (this.doneRes != 2) { return (V) this.result; } throw new ExecutionException((Throwable) this.result); } @Override // java.util.concurrent.Future public synchronized boolean cancel(boolean z) { if (isDone()) { return false; } this.doneRes = 3; return true; } public synchronized boolean set(V v) { if (isDone()) { return false; } this.result = v; this.doneRes = 1; return true; } public synchronized boolean setException(Throwable th) { if (isDone()) { return false; } this.result = th; this.doneRes = 2; return true; } } }