@Test public void testEmptyQueue() { Queue<Integer> queue = Queues.<Integer> get(0).get(); List<Integer> values = Arrays.asList(1, 2, 3); assertThat(queue.add(1)).isFalse(); assertThat(queue.addAll(values)).isFalse(); assertThat(queue.offer(1)).isFalse(); assertThat(queue.peek()).isNull(); assertThat(queue.poll()).isNull(); assertThat(queue.contains(1)).isFalse(); assertThat(queue.iterator().hasNext()).isFalse(); assertThatThrownBy(queue::element).isInstanceOf(NoSuchElementException.class); assertThatThrownBy(queue::remove).isInstanceOf(NoSuchElementException.class); assertThat(queue.remove(1)).isFalse(); assertThat(queue.containsAll(values)).isFalse(); assertThat(queue.retainAll(values)).isFalse(); assertThat(queue.removeAll(values)).isFalse(); queue.clear(); assertThat(queue).hasSize(0); assertThat(queue.toArray()).isEmpty(); assertThat(queue.toArray(new Integer[0])).isEmpty(); Integer[] array = new Integer[] { 4, 5, 6 }; assertThat(queue.toArray(array)).containsExactly(null, 5, 6); assertThat(queue).isEmpty(); }
public static <T> Supplier<Queue<T>> get(int bufferSize) { if (bufferSize == BUFFER_XS) { return XS_QUEUE_SUPPLIER; } if (bufferSize == BUFFER_S) { return S_QUEUE_SUPPLIER; } if (bufferSize == 1) { return SINGLETON_QUEUE_SUPPLIER; } if (bufferSize == 0) { return EMPTY_QUEUE_SUPPLIER; } final int computedSize = Math.max(8, bufferSize); if (computedSize > TO_LARGE_TO_BE_BOUNDED) { return UNBOUNDED_QUEUE_SUPPLIER; } else { return () -> new SpscArrayQueue<>(computedSize); } }
Queues { public static <T> Supplier<Queue<T>> get(int bufferSize) { if (bufferSize == BUFFER_XS) { return XS_QUEUE_SUPPLIER; } if (bufferSize == BUFFER_S) { return S_QUEUE_SUPPLIER; } if (bufferSize == 1) { return SINGLETON_QUEUE_SUPPLIER; } if (bufferSize == 0) { return EMPTY_QUEUE_SUPPLIER; } final int computedSize = Math.max(8, bufferSize); if (computedSize > TO_LARGE_TO_BE_BOUNDED) { return UNBOUNDED_QUEUE_SUPPLIER; } else { return () -> new SpscArrayQueue<>(computedSize); } } }
Queues { public static <T> Supplier<Queue<T>> get(int bufferSize) { if (bufferSize == BUFFER_XS) { return XS_QUEUE_SUPPLIER; } if (bufferSize == BUFFER_S) { return S_QUEUE_SUPPLIER; } if (bufferSize == 1) { return SINGLETON_QUEUE_SUPPLIER; } if (bufferSize == 0) { return EMPTY_QUEUE_SUPPLIER; } final int computedSize = Math.max(8, bufferSize); if (computedSize > TO_LARGE_TO_BE_BOUNDED) { return UNBOUNDED_QUEUE_SUPPLIER; } else { return () -> new SpscArrayQueue<>(computedSize); } } private  Queues(); }
Queues { public static <T> Supplier<Queue<T>> get(int bufferSize) { if (bufferSize == BUFFER_XS) { return XS_QUEUE_SUPPLIER; } if (bufferSize == BUFFER_S) { return S_QUEUE_SUPPLIER; } if (bufferSize == 1) { return SINGLETON_QUEUE_SUPPLIER; } if (bufferSize == 0) { return EMPTY_QUEUE_SUPPLIER; } final int computedSize = Math.max(8, bufferSize); if (computedSize > TO_LARGE_TO_BE_BOUNDED) { return UNBOUNDED_QUEUE_SUPPLIER; } else { return () -> new SpscArrayQueue<>(computedSize); } } private  Queues(); static Supplier<Queue<T>> getXsQueueSupplier(); static Supplier<Queue<T>> get(int bufferSize); @SuppressWarnings("unchecked") static Supplier<Queue<T>> unbounded(int size); static Queue<T> createMpscQueue(); }
Queues { public static <T> Supplier<Queue<T>> get(int bufferSize) { if (bufferSize == BUFFER_XS) { return XS_QUEUE_SUPPLIER; } if (bufferSize == BUFFER_S) { return S_QUEUE_SUPPLIER; } if (bufferSize == 1) { return SINGLETON_QUEUE_SUPPLIER; } if (bufferSize == 0) { return EMPTY_QUEUE_SUPPLIER; } final int computedSize = Math.max(8, bufferSize); if (computedSize > TO_LARGE_TO_BE_BOUNDED) { return UNBOUNDED_QUEUE_SUPPLIER; } else { return () -> new SpscArrayQueue<>(computedSize); } } private  Queues(); static Supplier<Queue<T>> getXsQueueSupplier(); static Supplier<Queue<T>> get(int bufferSize); @SuppressWarnings("unchecked") static Supplier<Queue<T>> unbounded(int size); static Queue<T> createMpscQueue(); static final int TO_LARGE_TO_BE_BOUNDED; static final int BUFFER_XS; static final int BUFFER_S; }