Class QueueUtils
- java.lang.Object
-
- io.microsphere.collection.QueueUtils
-
-
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 booleanisDeque(java.lang.Iterable<?> values)Checks whether the specifiedIterableis an instance ofDeque.static booleanisQueue(java.lang.Class<?> type)Checks whether the specifiedtypeis an instance ofQueue.static booleanisQueue(java.lang.Object values)Checks whether the specifiedIterableis an instance ofQueue.static <E> java.util.concurrent.ArrayBlockingQueue<E>newArrayBlockingQueue(int capacity)Creates a new emptyArrayBlockingQueueinstance with the specified capacity.static <E> java.util.concurrent.ArrayBlockingQueue<E>newArrayBlockingQueue(int capacity, java.util.Collection<? extends E> elements)Creates a newArrayBlockingQueueinstance from the specifiedCollection.static <E> java.util.ArrayDeque<E>newArrayDeque()Creates a new emptyArrayDequeinstance.static <E> java.util.ArrayDeque<E>newArrayDeque(int initialCapacity)Creates a newArrayDequeinstance with the specified initial capacity.static <E> java.util.ArrayDeque<E>newArrayDeque(E... elements)Creates a newArrayDequeinstance containing the specified elements.static <E> java.util.ArrayDeque<E>newArrayDeque(java.util.Collection<? extends E> elements)Creates a newArrayDequeinstance containing all elements from the specifiedCollection.static <E> java.util.concurrent.ConcurrentLinkedQueue<E>newConcurrentLinkedQueue()Creates a new emptyConcurrentLinkedQueueinstance.static <E> java.util.concurrent.ConcurrentLinkedQueue<E>newConcurrentLinkedQueue(java.util.Collection<? extends E> elements)Creates a newConcurrentLinkedQueueinstance from the specifiedCollection.static <E extends java.util.concurrent.Delayed>
java.util.concurrent.DelayQueue<E>newDelayQueue()Creates a new emptyDelayQueueinstance.static <E> java.util.concurrent.LinkedBlockingQueue<E>newLinkedBlockingQueue()Creates a new emptyLinkedBlockingQueueinstance.static <E> java.util.concurrent.LinkedBlockingQueue<E>newLinkedBlockingQueue(int capacity)Creates a newLinkedBlockingQueueinstance with the specified capacity.static <E> java.util.concurrent.LinkedBlockingQueue<E>newLinkedBlockingQueue(java.util.Collection<? extends E> elements)Creates a newLinkedBlockingQueueinstance from the specifiedCollection.static <E> java.util.concurrent.LinkedTransferQueue<E>newLinkedTransferQueue()Creates a new emptyLinkedTransferQueueinstance.static <E> java.util.concurrent.LinkedTransferQueue<E>newLinkedTransferQueue(java.util.Collection<? extends E> elements)Creates a newLinkedTransferQueueinstance from the specifiedCollection.static <E> java.util.concurrent.PriorityBlockingQueue<E>newPriorityBlockingQueue()Creates a new emptyPriorityBlockingQueueinstance.static <E> java.util.concurrent.PriorityBlockingQueue<E>newPriorityBlockingQueue(java.util.Collection<? extends E> elements)Creates a new {PriorityBlockingQueueinstance from the specifiedCollection.static <E> java.util.PriorityQueue<E>newPriorityQueue()Creates a new emptyPriorityQueueinstance.static <E> java.util.PriorityQueue<E>newPriorityQueue(int initialCapacity)Creates a newPriorityQueueinstance with the specified initial capacity.static <E> java.util.PriorityQueue<E>newPriorityQueue(java.util.Collection<? extends E> elements)Creates a newPriorityQueueinstance from the specifiedCollection.static <E> java.util.PriorityQueue<E>newPriorityQueue(java.util.Comparator<? super E> comparator)Creates a newPriorityQueueinstance with the specified comparator.static <E> java.util.concurrent.SynchronousQueue<E>newSynchronousQueue()Creates a new emptySynchronousQueueinstance.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.
-
-
-
Method Detail
-
isQueue
public static boolean isQueue(@Nullable java.lang.Object values)Checks whether the specifiedIterableis an instance ofQueue.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- theIterableto check- Returns:
trueif the givenIterableis aQueue,falseotherwise
-
isQueue
public static boolean isQueue(@Nullable java.lang.Class<?> type)Checks whether the specifiedtypeis an instance ofQueue.Example Usage
boolean result = isQueue(LinkedList.class); // returns true result = isQueue(ArrayList.class); // returns false- Parameters:
type- thetypeto check- Returns:
trueif the giventypeis aQueue,falseotherwise
-
isDeque
public static boolean isDeque(java.lang.Iterable<?> values)
Checks whether the specifiedIterableis an instance ofDeque.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- theIterableto check- Returns:
trueif the givenIterableis aDeque,falseotherwise
-
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 anUnsupportedOperationException.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 anUnsupportedOperationException.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 anUnsupportedOperationExceptiondepending 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
ArrayDequewith the given elements and then wraps it in an unmodifiable view usingunmodifiableQueue(Queue). The resulting queue is immutable, so any attempt to modify it will result in anUnsupportedOperationException.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 emptyArrayDequeinstance.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
ArrayDequeinstance
-
newArrayDeque
@Nonnull public static <E> java.util.ArrayDeque<E> newArrayDeque(int initialCapacity)
Creates a newArrayDequeinstance 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
ArrayDequeinstance 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 newArrayDequeinstance 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
ArrayDequeinstance containing the specified elements
-
newArrayDeque
@Nonnull public static <E> java.util.ArrayDeque<E> newArrayDeque(java.util.Collection<? extends E> elements)
Creates a newArrayDequeinstance containing all elements from the specifiedCollection.This method delegates to the
ArrayDequeconstructor 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
ArrayDequeinstance containing all elements from the provided collection
-
newPriorityQueue
@Nonnull public static <E> java.util.PriorityQueue<E> newPriorityQueue()
Creates a new emptyPriorityQueueinstance.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 newPriorityQueueinstance 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
PriorityQueuewith the specified initial capacity
-
newPriorityQueue
@Nonnull public static <E> java.util.PriorityQueue<E> newPriorityQueue(java.util.Comparator<? super E> comparator)
Creates a newPriorityQueueinstance 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
PriorityQueuewith the specified comparator
-
newPriorityQueue
@Nonnull public static <E> java.util.PriorityQueue<E> newPriorityQueue(java.util.Collection<? extends E> elements)
Creates a newPriorityQueueinstance from the specifiedCollection.This method converts the given
Collectioninto aPriorityQueue.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
PriorityQueuecontaining all elements from the collection
-
newConcurrentLinkedQueue
@Nonnull public static <E> java.util.concurrent.ConcurrentLinkedQueue<E> newConcurrentLinkedQueue()
Creates a new emptyConcurrentLinkedQueueinstance.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 newConcurrentLinkedQueueinstance from the specifiedCollection.This method converts the given
Collectioninto aConcurrentLinkedQueue.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
ConcurrentLinkedQueuecontaining all elements from the collection
-
newLinkedBlockingQueue
@Nonnull public static <E> java.util.concurrent.LinkedBlockingQueue<E> newLinkedBlockingQueue()
Creates a new emptyLinkedBlockingQueueinstance.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 newLinkedBlockingQueueinstance 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
LinkedBlockingQueuewith the specified capacity
-
newLinkedBlockingQueue
@Nonnull public static <E> java.util.concurrent.LinkedBlockingQueue<E> newLinkedBlockingQueue(java.util.Collection<? extends E> elements)
Creates a newLinkedBlockingQueueinstance from the specifiedCollection.This method converts the given
Collectioninto aLinkedBlockingQueue.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
LinkedBlockingQueuecontaining all elements from the collection
-
newArrayBlockingQueue
@Nonnull public static <E> java.util.concurrent.ArrayBlockingQueue<E> newArrayBlockingQueue(int capacity)
Creates a new emptyArrayBlockingQueueinstance 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
ArrayBlockingQueuewith the specified capacity
-
newArrayBlockingQueue
@Nonnull public static <E> java.util.concurrent.ArrayBlockingQueue<E> newArrayBlockingQueue(int capacity, java.util.Collection<? extends E> elements)Creates a newArrayBlockingQueueinstance from the specifiedCollection.This method converts the given
Collectioninto anArrayBlockingQueue.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 queueelements- the collection of elements to add to the queue, may be null or empty- Returns:
- a new
ArrayBlockingQueuecontaining all elements from the collection
-
newPriorityBlockingQueue
@Nonnull public static <E> java.util.concurrent.PriorityBlockingQueue<E> newPriorityBlockingQueue()
Creates a new emptyPriorityBlockingQueueinstance.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 {PriorityBlockingQueueinstance from the specifiedCollection.This method converts the given
Collectioninto aPriorityBlockingQueue.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
PriorityBlockingQueuecontaining all elements from the collection
-
newDelayQueue
@Nonnull public static <E extends java.util.concurrent.Delayed> java.util.concurrent.DelayQueue<E> newDelayQueue()
Creates a new emptyDelayQueueinstance.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 emptySynchronousQueueinstance.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 emptyLinkedTransferQueueinstance.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 newLinkedTransferQueueinstance from the specifiedCollection.This method converts the given
Collectioninto aLinkedTransferQueue.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
LinkedTransferQueuecontaining all elements from the collection
-
-