package com.google.common.util.concurrent; import com.google.common.base.Preconditions; import java.lang.Thread; import java.util.Locale; import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicLong; /* loaded from: classes2.dex */ public final class ThreadFactoryBuilder { private String nameFormat = null; private Boolean daemon = null; private Integer priority = null; private Thread.UncaughtExceptionHandler uncaughtExceptionHandler = null; private ThreadFactory backingThreadFactory = null; public final ThreadFactoryBuilder setNameFormat(String str) { format(str, 0); this.nameFormat = str; return this; } public final ThreadFactoryBuilder setDaemon(boolean z) { this.daemon = Boolean.valueOf(z); return this; } public final ThreadFactoryBuilder setPriority(int i) { Preconditions.checkArgument(i > 0, "Thread priority (%s) must be >= %s", i, 1); Preconditions.checkArgument(i <= 10, "Thread priority (%s) must be <= %s", i, 10); this.priority = Integer.valueOf(i); return this; } public final ThreadFactoryBuilder setUncaughtExceptionHandler(Thread.UncaughtExceptionHandler uncaughtExceptionHandler) { this.uncaughtExceptionHandler = (Thread.UncaughtExceptionHandler) Preconditions.checkNotNull(uncaughtExceptionHandler); return this; } public final ThreadFactoryBuilder setThreadFactory(ThreadFactory threadFactory) { this.backingThreadFactory = (ThreadFactory) Preconditions.checkNotNull(threadFactory); return this; } public final ThreadFactory build() { return doBuild(this); } private static ThreadFactory doBuild(ThreadFactoryBuilder threadFactoryBuilder) { String str = threadFactoryBuilder.nameFormat; Boolean bool = threadFactoryBuilder.daemon; Integer num = threadFactoryBuilder.priority; Thread.UncaughtExceptionHandler uncaughtExceptionHandler = threadFactoryBuilder.uncaughtExceptionHandler; ThreadFactory threadFactory = threadFactoryBuilder.backingThreadFactory; if (threadFactory == null) { threadFactory = Executors.defaultThreadFactory(); } return new ThreadFactory(threadFactory, str, str != null ? new AtomicLong(0L) : null, bool, num, uncaughtExceptionHandler) { // from class: com.google.common.util.concurrent.ThreadFactoryBuilder.1 final ThreadFactory val$backingThreadFactory; final AtomicLong val$count; final Boolean val$daemon; final String val$nameFormat; final Integer val$priority; final Thread.UncaughtExceptionHandler val$uncaughtExceptionHandler; { this.val$backingThreadFactory = threadFactory; this.val$nameFormat = str; this.val$count = r3; this.val$daemon = bool; this.val$priority = num; this.val$uncaughtExceptionHandler = uncaughtExceptionHandler; } @Override // java.util.concurrent.ThreadFactory public Thread newThread(Runnable runnable) { Thread newThread = this.val$backingThreadFactory.newThread(runnable); String str2 = this.val$nameFormat; if (str2 != null) { newThread.setName(ThreadFactoryBuilder.format(str2, Long.valueOf(this.val$count.getAndIncrement()))); } Boolean bool2 = this.val$daemon; if (bool2 != null) { newThread.setDaemon(bool2.booleanValue()); } Integer num2 = this.val$priority; if (num2 != null) { newThread.setPriority(num2.intValue()); } Thread.UncaughtExceptionHandler uncaughtExceptionHandler2 = this.val$uncaughtExceptionHandler; if (uncaughtExceptionHandler2 != null) { newThread.setUncaughtExceptionHandler(uncaughtExceptionHandler2); } return newThread; } }; } /* JADX INFO: Access modifiers changed from: private */ public static String format(String str, Object... objArr) { return String.format(Locale.ROOT, str, objArr); } }