package com.google.common.collect; import com.google.common.base.Preconditions; import java.util.ArrayDeque; import java.util.Collection; import java.util.Deque; import java.util.PriorityQueue; import java.util.Queue; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.TimeUnit; /* loaded from: classes2.dex */ public final class Queues { private Queues() { } public static ArrayBlockingQueue newArrayBlockingQueue(int i) { return new ArrayBlockingQueue<>(i); } public static ArrayDeque newArrayDeque() { return new ArrayDeque<>(); } public static ArrayDeque newArrayDeque(Iterable iterable) { if (iterable instanceof Collection) { return new ArrayDeque<>((Collection) iterable); } ArrayDeque arrayDeque = new ArrayDeque<>(); Iterables.addAll(arrayDeque, iterable); return arrayDeque; } public static ConcurrentLinkedQueue newConcurrentLinkedQueue() { return new ConcurrentLinkedQueue<>(); } public static ConcurrentLinkedQueue newConcurrentLinkedQueue(Iterable iterable) { if (iterable instanceof Collection) { return new ConcurrentLinkedQueue<>((Collection) iterable); } ConcurrentLinkedQueue concurrentLinkedQueue = new ConcurrentLinkedQueue<>(); Iterables.addAll(concurrentLinkedQueue, iterable); return concurrentLinkedQueue; } public static LinkedBlockingDeque newLinkedBlockingDeque() { return new LinkedBlockingDeque<>(); } public static LinkedBlockingDeque newLinkedBlockingDeque(int i) { return new LinkedBlockingDeque<>(i); } public static LinkedBlockingDeque newLinkedBlockingDeque(Iterable iterable) { if (iterable instanceof Collection) { return new LinkedBlockingDeque<>((Collection) iterable); } LinkedBlockingDeque linkedBlockingDeque = new LinkedBlockingDeque<>(); Iterables.addAll(linkedBlockingDeque, iterable); return linkedBlockingDeque; } public static LinkedBlockingQueue newLinkedBlockingQueue() { return new LinkedBlockingQueue<>(); } public static LinkedBlockingQueue newLinkedBlockingQueue(int i) { return new LinkedBlockingQueue<>(i); } public static LinkedBlockingQueue newLinkedBlockingQueue(Iterable iterable) { if (iterable instanceof Collection) { return new LinkedBlockingQueue<>((Collection) iterable); } LinkedBlockingQueue linkedBlockingQueue = new LinkedBlockingQueue<>(); Iterables.addAll(linkedBlockingQueue, iterable); return linkedBlockingQueue; } public static PriorityBlockingQueue newPriorityBlockingQueue() { return new PriorityBlockingQueue<>(); } public static PriorityBlockingQueue newPriorityBlockingQueue(Iterable iterable) { if (iterable instanceof Collection) { return new PriorityBlockingQueue<>((Collection) iterable); } PriorityBlockingQueue priorityBlockingQueue = new PriorityBlockingQueue<>(); Iterables.addAll(priorityBlockingQueue, iterable); return priorityBlockingQueue; } public static PriorityQueue newPriorityQueue() { return new PriorityQueue<>(); } public static PriorityQueue newPriorityQueue(Iterable iterable) { if (iterable instanceof Collection) { return new PriorityQueue<>((Collection) iterable); } PriorityQueue priorityQueue = new PriorityQueue<>(); Iterables.addAll(priorityQueue, iterable); return priorityQueue; } public static SynchronousQueue newSynchronousQueue() { return new SynchronousQueue<>(); } public static int drain(BlockingQueue blockingQueue, Collection collection, int i, long j, TimeUnit timeUnit) throws InterruptedException { Preconditions.checkNotNull(collection); long nanoTime = System.nanoTime(); long nanos = timeUnit.toNanos(j); int i2 = 0; while (i2 < i) { i2 += blockingQueue.drainTo(collection, i - i2); if (i2 < i) { E poll = blockingQueue.poll((nanoTime + nanos) - System.nanoTime(), TimeUnit.NANOSECONDS); if (poll == null) { break; } collection.add(poll); i2++; } } return i2; } public static int drainUninterruptibly(BlockingQueue blockingQueue, Collection collection, int i, long j, TimeUnit timeUnit) { E poll; Preconditions.checkNotNull(collection); long nanoTime = System.nanoTime(); long nanos = timeUnit.toNanos(j); int i2 = 0; boolean z = false; while (i2 < i) { try { i2 += blockingQueue.drainTo(collection, i - i2); if (i2 < i) { while (true) { try { poll = blockingQueue.poll((nanoTime + nanos) - System.nanoTime(), TimeUnit.NANOSECONDS); break; } catch (InterruptedException unused) { z = true; } } if (poll == null) { break; } collection.add(poll); i2++; } } finally { if (z) { Thread.currentThread().interrupt(); } } } return i2; } public static Queue synchronizedQueue(Queue queue) { return Synchronized.queue(queue, null); } public static Deque synchronizedDeque(Deque deque) { return Synchronized.deque(deque, null); } }