Class QueueUtils

  • All Implemented Interfaces:
    Utils

    public abstract class QueueUtils
    extends java.lang.Object
    implements Utils
    The utilities class for Java Queue
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    Queue
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.Deque<?> EMPTY_DEQUE  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <E> java.util.Deque<E> emptyDeque()
      Returns an empty immutable deque instance.
      static <E> java.util.Queue<E> emptyQueue()
      Returns an empty immutable queue instance.
      static boolean isDeque​(java.lang.Iterable<?> values)
      Checks whether the specified Iterable is an instance of Deque.
      static boolean isQueue​(java.lang.Class<?> type)
      Checks whether the specified type is an instance of Queue.
      static boolean isQueue​(java.lang.Object values)
      Checks whether the specified Iterable is an instance of Queue.
      static <E> java.util.concurrent.ArrayBlockingQueue<E> newArrayBlockingQueue​(int capacity)
      Creates a new empty ArrayBlockingQueue instance with the specified capacity.
      static <E> java.util.concurrent.ArrayBlockingQueue<E> newArrayBlockingQueue​(int capacity, java.util.Collection<? extends E> elements)
      Creates a new ArrayBlockingQueue instance from the specified Collection.
      static <E> java.util.ArrayDeque<E> newArrayDeque()
      Creates a new empty ArrayDeque instance.
      static <E> java.util.ArrayDeque<E> newArrayDeque​(int initialCapacity)
      Creates a new ArrayDeque instance with the specified initial capacity.
      static <E> java.util.ArrayDeque<E> newArrayDeque​(E... elements)
      Creates a new ArrayDeque instance containing the specified elements.
      static <E> java.util.ArrayDeque<E> newArrayDeque​(java.util.Collection<? extends E> elements)
      Creates a new ArrayDeque instance containing all elements from the specified Collection.
      static <E> java.util.concurrent.ConcurrentLinkedQueue<E> newConcurrentLinkedQueue()
      Creates a new empty ConcurrentLinkedQueue instance.
      static <E> java.util.concurrent.ConcurrentLinkedQueue<E> newConcurrentLinkedQueue​(java.util.Collection<? extends E> elements)
      Creates a new ConcurrentLinkedQueue instance from the specified Collection.
      static <E extends java.util.concurrent.Delayed>
      java.util.concurrent.DelayQueue<E>
      newDelayQueue()
      Creates a new empty DelayQueue instance.
      static <E> java.util.concurrent.LinkedBlockingQueue<E> newLinkedBlockingQueue()
      Creates a new empty LinkedBlockingQueue instance.
      static <E> java.util.concurrent.LinkedBlockingQueue<E> newLinkedBlockingQueue​(int capacity)
      Creates a new LinkedBlockingQueue instance with the specified capacity.
      static <E> java.util.concurrent.LinkedBlockingQueue<E> newLinkedBlockingQueue​(java.util.Collection<? extends E> elements)
      Creates a new LinkedBlockingQueue instance from the specified Collection.
      static <E> java.util.concurrent.LinkedTransferQueue<E> newLinkedTransferQueue()
      Creates a new empty LinkedTransferQueue instance.
      static <E> java.util.concurrent.LinkedTransferQueue<E> newLinkedTransferQueue​(java.util.Collection<? extends E> elements)
      Creates a new LinkedTransferQueue instance from the specified Collection.
      static <E> java.util.concurrent.PriorityBlockingQueue<E> newPriorityBlockingQueue()
      Creates a new empty PriorityBlockingQueue instance.
      static <E> java.util.concurrent.PriorityBlockingQueue<E> newPriorityBlockingQueue​(java.util.Collection<? extends E> elements)
      Creates a new {PriorityBlockingQueue instance from the specified Collection.
      static <E> java.util.PriorityQueue<E> newPriorityQueue()
      Creates a new empty PriorityQueue instance.
      static <E> java.util.PriorityQueue<E> newPriorityQueue​(int initialCapacity)
      Creates a new PriorityQueue instance with the specified initial capacity.
      static <E> java.util.PriorityQueue<E> newPriorityQueue​(java.util.Collection<? extends E> elements)
      Creates a new PriorityQueue instance from the specified Collection.
      static <E> java.util.PriorityQueue<E> newPriorityQueue​(java.util.Comparator<? super E> comparator)
      Creates a new PriorityQueue instance with the specified comparator.
      static <E> java.util.concurrent.SynchronousQueue<E> newSynchronousQueue()
      Creates a new empty SynchronousQueue instance.
      static <E> java.util.Queue<E> ofQueue​(E... elements)
      Creates an immutable queue containing the specified elements.
      static <E> java.util.Deque<E> reversedDeque​(java.util.Deque<E> deque)
      Returns a reversed view of the specified deque.
      static <E> java.util.Deque<E> singletonDeque​(E element)
      Returns an immutable deque containing only the specified element.
      static <E> java.util.Queue<E> singletonQueue​(E element)
      Returns an immutable queue containing only the specified element.
      static <E> java.util.Deque<E> unmodifiableDeque​(java.util.Deque<E> deque)
      Returns an unmodifiable view of the given deque.
      static <E> java.util.Queue<E> unmodifiableQueue​(java.util.Queue<E> queue)
      Returns an unmodifiable view of the given queue.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • EMPTY_DEQUE

        public static final java.util.Deque<?> EMPTY_DEQUE
    • Method Detail

      • isQueue

        public static boolean isQueue​(@Nullable
                                      java.lang.Object values)
        Checks whether the specified Iterable is an instance of Queue.

        Example Usage

        
         Queue<String> queue = new LinkedList<>();
         boolean result = isQueue(queue); // returns true
        
         List<String> list = new ArrayList<>();
         result = isQueue(list); // returns false
         
        Parameters:
        values - the Iterable to check
        Returns:
        true if the given Iterable is a Queue, false otherwise
      • isQueue

        public static boolean isQueue​(@Nullable
                                      java.lang.Class<?> type)
        Checks whether the specified type is an instance of Queue.

        Example Usage

        
         boolean result = isQueue(LinkedList.class); // returns true
        
         result = isQueue(ArrayList.class); // returns false
         
        Parameters:
        type - the type to check
        Returns:
        true if the given type is a Queue, false otherwise
      • isDeque

        public static boolean isDeque​(java.lang.Iterable<?> values)
        Checks whether the specified Iterable is an instance of Deque.

        Example Usage

        
         Deque<String> deque = new LinkedList<>();
         boolean result = isDeque(deque); // returns true
        
         List<String> list = new ArrayList<>();
         result = isDeque(list); // returns false
         
        Parameters:
        values - the Iterable to check
        Returns:
        true if the given Iterable is a Deque, false otherwise
      • emptyQueue

        @Nonnull
        @Immutable
        public static <E> java.util.Queue<E> emptyQueue()
        Returns an empty immutable queue instance.

        Example Usage

        
         Queue<String> empty = emptyQueue();
         boolean isEmpty = empty.isEmpty(); // returns true
         int size = empty.size(); // returns 0
         
        Type Parameters:
        E - the type of elements held in the queue
        Returns:
        an empty immutable queue instance
      • emptyDeque

        @Nonnull
        @Immutable
        public static <E> java.util.Deque<E> emptyDeque()
        Returns an empty immutable deque instance.

        Example Usage

        
         Deque<String> empty = emptyDeque();
         boolean isEmpty = empty.isEmpty(); // returns true
         int size = empty.size(); // returns 0
         
        Type Parameters:
        E - the type of elements held in the deque
        Returns:
        an empty immutable deque instance
      • unmodifiableQueue

        @Nonnull
        public static <E> java.util.Queue<E> unmodifiableQueue​(java.util.Queue<E> queue)
        Returns an unmodifiable view of the given queue.

        This method wraps the provided queue in an UnmodifiableQueue, which prevents any modifications to the queue. Any attempt to modify the returned queue will result in an UnsupportedOperationException.

        Example Usage

        
         Queue<String> mutableQueue = new LinkedList<>();
         mutableQueue.add("Hello");
         Queue<String> unmodifiable = unmodifiableQueue(mutableQueue);
        
         unmodifiable.add("World"); // throws UnsupportedOperationException
         
        Type Parameters:
        E - the type of elements held in the queue
        Parameters:
        queue - the queue to be made unmodifiable, must not be null
        Returns:
        an unmodifiable view of the specified queue
        Throws:
        java.lang.NullPointerException - if the provided queue is null
      • unmodifiableDeque

        @Nonnull
        @Immutable
        public static <E> java.util.Deque<E> unmodifiableDeque​(java.util.Deque<E> deque)
        Returns an unmodifiable view of the given deque.

        This method wraps the provided deque in an UnmodifiableDeque, which prevents any modifications to the deque. Any attempt to modify the returned deque will result in an UnsupportedOperationException.

        Example Usage

        
         Deque<String> mutableDeque = new LinkedList<>();
         mutableDeque.add("Hello");
         Deque<String> unmodifiable = unmodifiableDeque(mutableDeque);
        
         unmodifiable.addFirst("World"); // throws UnsupportedOperationException
         
        Type Parameters:
        E - the type of elements held in the deque
        Parameters:
        deque - the deque to be made unmodifiable, must not be null
        Returns:
        an unmodifiable view of the specified deque
        Throws:
        java.lang.NullPointerException - if the provided deque is null
      • singletonQueue

        @Nonnull
        @Immutable
        public static <E> java.util.Queue<E> singletonQueue​(E element)
        Returns an immutable queue containing only the specified element.

        The returned queue is a singleton instance that holds exactly one element. It is immutable, so any attempt to modify the queue will result in an UnsupportedOperationException.

        Example Usage

        
         Queue<String> singleton = singletonQueue("Hello");
         boolean isEmpty = singleton.isEmpty(); // returns false
         int size = singleton.size(); // returns 1
         String value = singleton.poll(); // returns "Hello"
         
        Type Parameters:
        E - the type of the queue's element
        Parameters:
        element - the sole element to be stored in the returned queue
        Returns:
        a singleton immutable queue containing the specified element
      • singletonDeque

        @Nonnull
        @Immutable
        public static <E> java.util.Deque<E> singletonDeque​(E element)
        Returns an immutable deque containing only the specified element.

        The returned deque is a singleton instance that holds exactly one element. It is immutable, so any attempt to modify the deque will result in an UnsupportedOperationException.

        Example Usage

        
         Deque<String> singleton = singletonDeque("Hello");
         boolean isEmpty = singleton.isEmpty(); // returns false
         int size = singleton.size(); // returns 1
         String value = singleton.pollFirst(); // returns "Hello"
         
        Type Parameters:
        E - the type of the deque's element
        Parameters:
        element - the sole element to be stored in the returned deque
        Returns:
        a singleton immutable deque containing the specified element
      • reversedDeque

        public static <E> java.util.Deque<E> reversedDeque​(java.util.Deque<E> deque)
        Returns a reversed view of the specified deque.

        This method wraps the provided deque in a ReversedDeque, which presents the elements in reverse order. Modifications to the original deque are reflected in the reversed view, and vice versa. However, attempts to modify the reversed view may result in an UnsupportedOperationException depending on the underlying implementation.

        Example Usage

        
         Deque<String> deque = new LinkedList<>();
         deque.addLast("A");
         deque.addLast("B");
         deque.addLast("C");
        
         Deque<String> reversed = reversedDeque(deque);
         String first = reversed.peekFirst(); // returns "C"
         String last = reversed.peekLast();   // returns "A"
        
         // Iterating through the reversed view
         for (String value : reversed) {
             System.out.println(value); // prints "C", "B", "A"
         }
         
        Type Parameters:
        E - the type of elements held in the deque
        Parameters:
        deque - the deque to be viewed in reverse order, must not be null
        Returns:
        a reversed view of the specified deque
        Throws:
        java.lang.NullPointerException - if the provided deque is null
      • ofQueue

        @Nonnull
        @Immutable
        public static <E> java.util.Queue<E> ofQueue​(E... elements)
        Creates an immutable queue containing the specified elements.

        This method first creates a new ArrayDeque with the given elements and then wraps it in an unmodifiable view using unmodifiableQueue(Queue). The resulting queue is immutable, so any attempt to modify it will result in an UnsupportedOperationException.

        Example Usage

        
         Queue<String> queue = ofQueue("Hello", "World");
         System.out.println(queue); // prints [Hello, World]
        
         Queue<Integer> emptyQueue = ofQueue();
         System.out.println(emptyQueue); // prints []
        
         queue.add("Java"); // throws UnsupportedOperationException
         
        Type Parameters:
        E - the type of elements held in the queue
        Parameters:
        elements - the elements to be added to the queue, can be null or empty
        Returns:
        an immutable queue containing the specified elements
      • newArrayDeque

        @Nonnull
        public static <E> java.util.ArrayDeque<E> newArrayDeque()
        Creates a new empty ArrayDeque instance.

        Example Usage

        
         ArrayDeque<String> deque = newArrayDeque();
         deque.add("Hello");
         deque.add("World");
         System.out.println(deque); // prints [Hello, World]
         
        Type Parameters:
        E - the type of elements held in the deque
        Returns:
        a new empty ArrayDeque instance
      • newArrayDeque

        @Nonnull
        public static <E> java.util.ArrayDeque<E> newArrayDeque​(int initialCapacity)
        Creates a new ArrayDeque instance with the specified initial capacity.

        Example Usage

        
         ArrayDeque<String> deque = newArrayDeque(16);
         deque.add("Hello");
         deque.add("World");
         System.out.println(deque); // prints [Hello, World]
         
        Type Parameters:
        E - the type of elements held in the deque
        Parameters:
        initialCapacity - the initial capacity of the deque
        Returns:
        a new ArrayDeque instance with the specified initial capacity
        Throws:
        java.lang.IllegalArgumentException - if the specified initial capacity is negative
      • newArrayDeque

        @Nonnull
        public static <E> java.util.ArrayDeque<E> newArrayDeque​(E... elements)
        Creates a new ArrayDeque instance containing the specified elements.

        Example Usage

        
         ArrayDeque<String> deque = newArrayDeque("Hello", "World");
         System.out.println(deque); // prints [Hello, World]
        
         ArrayDeque<Integer> emptyDeque = newArrayDeque();
         System.out.println(emptyDeque); // prints []
         
        Type Parameters:
        E - the type of elements held in the deque
        Parameters:
        elements - the elements to be added to the deque, can be null or empty
        Returns:
        a new ArrayDeque instance containing the specified elements
      • newArrayDeque

        @Nonnull
        public static <E> java.util.ArrayDeque<E> newArrayDeque​(java.util.Collection<? extends E> elements)
        Creates a new ArrayDeque instance containing all elements from the specified Collection.

        This method delegates to the ArrayDeque constructor that accepts a collection, ensuring all elements from the input collection are included in the resulting deque. The returned deque is modifiable and allows null elements.

        Example Usage

        
             List<String> list = Arrays.asList("Hello", "World");
             ArrayDeque<String> deque = QueueUtils.newArrayDeque(list);
             System.out.println(deque); // prints [Hello, World]
        
             Set<Integer> set = new HashSet<>(Arrays.asList(1, 2, 3));
             ArrayDeque<Integer> intDeque = QueueUtils.newArrayDeque(set);
             System.out.println(intDeque.size()); // prints 3
        
             ArrayDeque<String> emptyDeque = QueueUtils.newArrayDeque(Collections.emptyList());
             System.out.println(emptyDeque.isEmpty()); // prints true
         
        Type Parameters:
        E - the type of elements held in the deque
        Parameters:
        elements - the collection of elements to add to the deque, may be null or empty
        Returns:
        a new ArrayDeque instance containing all elements from the provided collection
      • newPriorityQueue

        @Nonnull
        public static <E> java.util.PriorityQueue<E> newPriorityQueue()
        Creates a new empty PriorityQueue instance.

        This method provides a convenient way to create an empty priority queue. The returned queue orders elements according to their natural ordering.

        Example Usage

        
             Queue<Integer> queue = QueueUtils.newPriorityQueue();
             System.out.println(queue.isEmpty()); // Output: true
        
             queue.add(3);
             queue.add(1);
             queue.add(2);
             System.out.println(queue.poll()); // Output: 1
         
        Type Parameters:
        E - the type of elements in the queue
        Returns:
        a new, empty PriorityQueue
      • newPriorityQueue

        @Nonnull
        public static <E> java.util.PriorityQueue<E> newPriorityQueue​(int initialCapacity)
        Creates a new PriorityQueue instance with the specified initial capacity.

        This method provides a convenient way to create a priority queue with a predefined initial size.

        Example Usage

        
             Queue<Integer> queue = QueueUtils.newPriorityQueue(10);
             System.out.println(queue.isEmpty()); // Output: true
         
        Type Parameters:
        E - the type of elements in the queue
        Parameters:
        initialCapacity - the initial capacity of the priority queue
        Returns:
        a new, empty PriorityQueue with the specified initial capacity
      • newPriorityQueue

        @Nonnull
        public static <E> java.util.PriorityQueue<E> newPriorityQueue​(java.util.Comparator<? super E> comparator)
        Creates a new PriorityQueue instance with the specified comparator.

        This method provides a convenient way to create a priority queue with a custom comparator.

        Example Usage

        
             Queue<Integer> queue = QueueUtils.newPriorityQueue(Comparator.reverseOrder());
             queue.add(1);
             queue.add(3);
             queue.add(2);
             System.out.println(queue.poll()); // Output: 3
         
        Type Parameters:
        E - the type of elements in the queue
        Parameters:
        comparator - the comparator to use for ordering elements
        Returns:
        a new, empty PriorityQueue with the specified comparator
      • newPriorityQueue

        @Nonnull
        public static <E> java.util.PriorityQueue<E> newPriorityQueue​(java.util.Collection<? extends E> elements)
        Creates a new PriorityQueue instance from the specified Collection.

        This method converts the given Collection into a PriorityQueue.

        Example Usage

        
             Collection<Integer> original = Arrays.asList(3, 1, 2);
             Queue<Integer> queue = QueueUtils.newPriorityQueue(original);
             System.out.println(queue.poll()); // Output: 1
         
        Type Parameters:
        E - the type of elements in the collection
        Parameters:
        elements - the collection of elements to add to the queue, may be null or empty
        Returns:
        a new PriorityQueue containing all elements from the collection
      • newConcurrentLinkedQueue

        @Nonnull
        public static <E> java.util.concurrent.ConcurrentLinkedQueue<E> newConcurrentLinkedQueue()
        Creates a new empty ConcurrentLinkedQueue instance.

        This method provides a convenient way to create an empty concurrent linked queue. The returned queue is thread-safe and allows for safe concurrent operations.

        Example Usage

        
             Queue<String> queue = QueueUtils.newConcurrentLinkedQueue();
             System.out.println(queue.isEmpty()); // Output: true
        
             queue.add("Hello");
             System.out.println(queue.poll()); // Output: Hello
         
        Type Parameters:
        E - the type of elements in the queue
        Returns:
        a new, empty ConcurrentLinkedQueue
      • newConcurrentLinkedQueue

        @Nonnull
        public static <E> java.util.concurrent.ConcurrentLinkedQueue<E> newConcurrentLinkedQueue​(java.util.Collection<? extends E> elements)
        Creates a new ConcurrentLinkedQueue instance from the specified Collection.

        This method converts the given Collection into a ConcurrentLinkedQueue.

        Example Usage

        
             Collection<String> original = Arrays.asList("a", "b", "c");
             Queue<String> queue = QueueUtils.newConcurrentLinkedQueue(original);
             System.out.println(queue); // Output: [a, b, c]
         
        Type Parameters:
        E - the type of elements in the collection
        Parameters:
        elements - the collection of elements to add to the queue, may be null or empty
        Returns:
        a new ConcurrentLinkedQueue containing all elements from the collection
      • newLinkedBlockingQueue

        @Nonnull
        public static <E> java.util.concurrent.LinkedBlockingQueue<E> newLinkedBlockingQueue()
        Creates a new empty LinkedBlockingQueue instance.

        This method provides a convenient way to create an empty linked blocking queue. The returned queue is thread-safe and allows for blocking operations.

        Example Usage

        
             Queue<String> queue = QueueUtils.newLinkedBlockingQueue();
             System.out.println(queue.isEmpty()); // Output: true
        
             queue.add("Hello");
             System.out.println(queue.poll()); // Output: Hello
         
        Type Parameters:
        E - the type of elements in the queue
        Returns:
        a new, empty LinkedBlockingQueue
      • newLinkedBlockingQueue

        @Nonnull
        public static <E> java.util.concurrent.LinkedBlockingQueue<E> newLinkedBlockingQueue​(int capacity)
        Creates a new LinkedBlockingQueue instance with the specified capacity.

        This method provides a convenient way to create a linked blocking queue with a predefined capacity.

        Example Usage

        
             Queue<String> queue = QueueUtils.newLinkedBlockingQueue(10);
             System.out.println(queue.isEmpty()); // Output: true
         
        Type Parameters:
        E - the type of elements in the queue
        Parameters:
        capacity - the capacity of the linked blocking queue
        Returns:
        a new, empty LinkedBlockingQueue with the specified capacity
      • newLinkedBlockingQueue

        @Nonnull
        public static <E> java.util.concurrent.LinkedBlockingQueue<E> newLinkedBlockingQueue​(java.util.Collection<? extends E> elements)
        Creates a new LinkedBlockingQueue instance from the specified Collection.

        This method converts the given Collection into a LinkedBlockingQueue.

        Example Usage

        
             Collection<String> original = Arrays.asList("a", "b", "c");
             Queue<String> queue = QueueUtils.newLinkedBlockingQueue(original);
             System.out.println(queue); // Output: [a, b, c]
         
        Type Parameters:
        E - the type of elements in the collection
        Parameters:
        elements - the collection of elements to add to the queue, may be null or empty
        Returns:
        a new LinkedBlockingQueue containing all elements from the collection
      • newArrayBlockingQueue

        @Nonnull
        public static <E> java.util.concurrent.ArrayBlockingQueue<E> newArrayBlockingQueue​(int capacity)
        Creates a new empty ArrayBlockingQueue instance with the specified capacity.

        This method provides a convenient way to create an empty array blocking queue with a predefined capacity.

        Example Usage

        
             Queue<String> queue = QueueUtils.newArrayBlockingQueue(10);
             System.out.println(queue.isEmpty()); // Output: true
        
             queue.add("Hello");
             System.out.println(queue.poll()); // Output: Hello
         
        Type Parameters:
        E - the type of elements in the queue
        Parameters:
        capacity - the capacity of the array blocking queue
        Returns:
        a new, empty ArrayBlockingQueue with the specified capacity
      • newArrayBlockingQueue

        @Nonnull
        public static <E> java.util.concurrent.ArrayBlockingQueue<E> newArrayBlockingQueue​(int capacity,
                                                                                           java.util.Collection<? extends E> elements)
        Creates a new ArrayBlockingQueue instance from the specified Collection.

        This method converts the given Collection into an ArrayBlockingQueue.

        Example Usage

        
             Collection<String> original = Arrays.asList("a", "b", "c");
             Queue<String> queue = QueueUtils.newArrayBlockingQueue(10, original);
             System.out.println(queue); // Output: [a, b, c]
         
        Type Parameters:
        E - the type of elements in the collection
        Parameters:
        capacity - the capacity of the array blocking queue
        elements - the collection of elements to add to the queue, may be null or empty
        Returns:
        a new ArrayBlockingQueue containing all elements from the collection
      • newPriorityBlockingQueue

        @Nonnull
        public static <E> java.util.concurrent.PriorityBlockingQueue<E> newPriorityBlockingQueue()
        Creates a new empty PriorityBlockingQueue instance.

        This method provides a convenient way to create an empty priority blocking queue. The returned queue is thread-safe and orders elements according to their natural ordering.

        Example Usage

        
             Queue<Integer> queue = QueueUtils.newPriorityBlockingQueue();
             System.out.println(queue.isEmpty()); // Output: true
        
             queue.add(3);
             queue.add(1);
             System.out.println(queue.poll()); // Output: 1
         
        Type Parameters:
        E - the type of elements in the queue
        Returns:
        a new, empty PriorityBlockingQueue
      • newPriorityBlockingQueue

        @Nonnull
        public static <E> java.util.concurrent.PriorityBlockingQueue<E> newPriorityBlockingQueue​(java.util.Collection<? extends E> elements)
        Creates a new {PriorityBlockingQueue instance from the specified Collection.

        This method converts the given Collection into a PriorityBlockingQueue.

        Example Usage

        
             Collection<Integer> original = Arrays.asList(3, 1, 2);
             Queue<Integer> queue = QueueUtils.newPriorityBlockingQueue(original);
             System.out.println(queue.poll()); // Output: 1
         
        Type Parameters:
        E - the type of elements in the collection
        Parameters:
        elements - the collection of elements to add to the queue, may be null or empty
        Returns:
        a new PriorityBlockingQueue containing all elements from the collection
      • newDelayQueue

        @Nonnull
        public static <E extends java.util.concurrent.Delayed> java.util.concurrent.DelayQueue<E> newDelayQueue()
        Creates a new empty DelayQueue instance.

        This method provides a convenient way to create an empty delay queue. The returned queue is an unbounded queue where elements can only be retrieved after their delay expires.

        Example Usage

        
             Queue<DelayedElement> queue = QueueUtils.newDelayQueue();
             System.out.println(queue.isEmpty()); // Output: true
         
        Type Parameters:
        E - the type of elements in the queue, must be of type Delayed
        Returns:
        a new, empty DelayQueue
      • newSynchronousQueue

        @Nonnull
        public static <E> java.util.concurrent.SynchronousQueue<E> newSynchronousQueue()
        Creates a new empty SynchronousQueue instance.

        This method provides a convenient way to create an empty synchronous queue. The returned queue is a blocking queue with zero capacity where each put operation must wait for a get operation.

        Example Usage

        
             Queue<String> queue = QueueUtils.newSynchronousQueue();
             System.out.println(queue.isEmpty()); // Output: true
         
        Type Parameters:
        E - the type of elements in the queue
        Returns:
        a new, empty SynchronousQueue
      • newLinkedTransferQueue

        @Nonnull
        public static <E> java.util.concurrent.LinkedTransferQueue<E> newLinkedTransferQueue()
        Creates a new empty LinkedTransferQueue instance.

        This method provides a convenient way to create an empty linked transfer queue. The returned queue is an unbounded queue for use with producers and consumers that may arrive and depart dynamically.

        Example Usage

        
             Queue<String> queue = QueueUtils.newLinkedTransferQueue();
             System.out.println(queue.isEmpty()); // Output: true
        
             queue.add("Hello");
             System.out.println(queue.poll()); // Output: Hello
         
        Type Parameters:
        E - the type of elements in the queue
        Returns:
        a new, empty LinkedTransferQueue
      • newLinkedTransferQueue

        @Nonnull
        public static <E> java.util.concurrent.LinkedTransferQueue<E> newLinkedTransferQueue​(java.util.Collection<? extends E> elements)
        Creates a new LinkedTransferQueue instance from the specified Collection.

        This method converts the given Collection into a LinkedTransferQueue.

        Example Usage

        
             Collection<String> original = Arrays.asList("a", "b", "c");
             Queue<String> queue = QueueUtils.newLinkedTransferQueue(original);
             System.out.println(queue); // Output: [a, b, c]
         
        Type Parameters:
        E - the type of elements in the collection
        Parameters:
        elements - the collection of elements to add to the queue, may be null or empty
        Returns:
        a new LinkedTransferQueue containing all elements from the collection