docs: @SuppressWarnings("unchecked")
      @Override
      public final <AT> AT[] toArray(AT[] a) {
          this.readLock.lock();
          try {
              // Verify the array size
              if (a.length < this.size) {
                  a =
                          (AT[])
                                  java.lang.reflect.Array.newInstance(
                                          a.getClass().getComponentType(), this.size);
              }
  
              // Trick to avoid generics warning
              final Object[] result = a;
  
              // Copy over all elements
              int index = 0;
              for (final Queue<T> queue : this.keyedQueues.values()) {
                  for (final T e : queue) {
                      result[index++] = e;
                  }
              }
  
              // If array is too big set next element null
              if (a.length > this.size) {
                  a[this.size] = null;
              }
  
              return a;
          } finally {
              this.readLock.unlock();
          }
      }