code: @Override
      @SuppressWarnings({"unchecked"})
      public <T> T[] toArray(final T[] destination) {
          requireNonNull(destination, ILLEGAL_DESTINATION_ARRAY);
  
          Supplier<T[]> copyRingBuffer = () -> {
              if (size == 0) {
                  return destination;
              }
              T[] result = destination;
              if (destination.length < size) {
                  result = (T[]) newInstance(result.getClass().getComponentType(), size);
              }
              if (headIndex <= tailIndex) {
                  System.arraycopy(ringBuffer, headIndex, result, 0, size);
              } else {
                  int toTheEnd = ringBuffer.length - headIndex;
                  System.arraycopy(ringBuffer, headIndex, result, 0, toTheEnd);
                  System.arraycopy(ringBuffer, 0, result, toTheEnd, tailIndex + 1);
              }
              return result;
          };
          return readConcurrentlyWithoutSpin(copyRingBuffer);
      }
docs: Returns an array containing all of the elements in this queue, in
  proper sequence; the runtime type of the returned array is that of
  the specified array.  If the queue fits in the specified array, it
  is returned therein.  Otherwise, a new array is allocated with the
  runtime type of the specified array and the size of this queue.
  
  <p>Like the {@link #toArray()} method, this method acts as bridge between
  array-based and collection-based APIs.  Further, this method allows
  precise control over the runtime type of the output array, and may,
  under certain circumstances, be used to save allocation costs.
  
  Note that {@code toArray(new Object[0])} is identical in function to
  {@code toArray()}.
  
  @param destination the array into which the elements of the queue are to
  be stored, if it is big enough; otherwise, a new array of the
  same runtime type is allocated for this purpose
  @return an array containing all of the elements in this queue
  @throws ArrayStoreException if the runtime type of the specified array
  is not a supertype of the runtime type of every element in
  this queue
  @throws NullPointerException if the specified array is null