package com.google.common.util.concurrent; import com.google.common.base.Preconditions; import com.google.common.base.Supplier; import java.util.concurrent.Callable; /* loaded from: classes2.dex */ public final class Callables { private Callables() { } public static Callable returning(T t) { return new Callable(t) { // from class: com.google.common.util.concurrent.Callables.1 final Object val$value; { this.val$value = t; } @Override // java.util.concurrent.Callable public T call() { return (T) this.val$value; } }; } public static AsyncCallable asAsyncCallable(Callable callable, ListeningExecutorService listeningExecutorService) { Preconditions.checkNotNull(callable); Preconditions.checkNotNull(listeningExecutorService); return new AsyncCallable(listeningExecutorService, callable) { // from class: com.google.common.util.concurrent.Callables.2 final Callable val$callable; final ListeningExecutorService val$listeningExecutorService; { this.val$listeningExecutorService = listeningExecutorService; this.val$callable = callable; } @Override // com.google.common.util.concurrent.AsyncCallable public ListenableFuture call() throws Exception { return this.val$listeningExecutorService.submit((Callable) this.val$callable); } }; } /* JADX INFO: Access modifiers changed from: package-private */ public static Callable threadRenaming(Callable callable, Supplier supplier) { Preconditions.checkNotNull(supplier); Preconditions.checkNotNull(callable); return new Callable(supplier, callable) { // from class: com.google.common.util.concurrent.Callables.3 final Callable val$callable; final Supplier val$nameSupplier; { this.val$nameSupplier = supplier; this.val$callable = callable; } @Override // java.util.concurrent.Callable public T call() throws Exception { Thread currentThread = Thread.currentThread(); String name = currentThread.getName(); boolean trySetName = Callables.trySetName((String) this.val$nameSupplier.get(), currentThread); try { return (T) this.val$callable.call(); } finally { if (trySetName) { Callables.trySetName(name, currentThread); } } } }; } /* JADX INFO: Access modifiers changed from: package-private */ public static Runnable threadRenaming(Runnable runnable, Supplier supplier) { Preconditions.checkNotNull(supplier); Preconditions.checkNotNull(runnable); return new Runnable(supplier, runnable) { // from class: com.google.common.util.concurrent.Callables.4 final Supplier val$nameSupplier; final Runnable val$task; { this.val$nameSupplier = supplier; this.val$task = runnable; } @Override // java.lang.Runnable public void run() { Thread currentThread = Thread.currentThread(); String name = currentThread.getName(); boolean trySetName = Callables.trySetName((String) this.val$nameSupplier.get(), currentThread); try { this.val$task.run(); } finally { if (trySetName) { Callables.trySetName(name, currentThread); } } } }; } /* JADX INFO: Access modifiers changed from: private */ public static boolean trySetName(String str, Thread thread) { try { thread.setName(str); return true; } catch (SecurityException unused) { return false; } } }