/** * Factory method to create an unmodifiable queue. * <p> * If the queue passed in is already unmodifiable, it is returned. * * @param <E> the type of the elements in the queue * @param queue the queue to decorate, must not be null * @return an unmodifiable Queue * @throws NullPointerException if queue is null */ public static <E> Queue<E> unmodifiableQueue(final Queue<? extends E> queue) { if (queue instanceof Unmodifiable) { @SuppressWarnings("unchecked") // safe to upcast final Queue<E> tmpQueue = (Queue<E>) queue; return tmpQueue; } return new UnmodifiableQueue<>(queue); }