@Test public void testCreationOfBoundedQueues() { Queue queue = Queues.get(2).get(); assertThat(getCapacity(queue)).isEqualTo(8); assertThat(queue).isInstanceOf(SpscArrayQueue.class); queue = Queues.get(8).get(); assertThat(getCapacity(queue)).isEqualTo(8); assertThat(queue).isInstanceOf(SpscArrayQueue.class); queue = Queues.get(10).get(); assertThat(getCapacity(queue)).isEqualTo(16); assertThat(queue).isInstanceOf(SpscArrayQueue.class); queue = Queues.get(BUFFER_XS).get(); assertThat(getCapacity(queue)).isEqualTo(32); assertThat(queue).isInstanceOf(SpscArrayQueue.class); queue = Queues.get(BUFFER_S).get(); assertThat(getCapacity(queue)).isEqualTo(256); assertThat(queue).isInstanceOf(SpscArrayQueue.class); queue = Queues.get(1).get(); assertThat(getCapacity(queue)).isEqualTo(1); assertThat(queue).isInstanceOf(SingletonQueue.class); queue = Queues.get(0).get(); assertThat(getCapacity(queue)).isEqualTo(0); assertThat(queue).isInstanceOf(EmptyQueue.class); queue = Queues.get(4).get(); assertThat(getCapacity(queue)).isEqualTo(8); assertThat(queue).isInstanceOf(SpscArrayQueue.class); }
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; }