docs: @Override
      public final int drainTo(Collection<? super T> c, int maxElements) {
          // Short circuit using read-lock
          if (this.isEmpty()) {
              return 0;
          }
  
          this.writeLock.lock();
          try {
              int count = 0;
  
              while (count < this.size && count < maxElements) {
                  final K key = this.getNextElementKey();
  
                  final Queue<T> queue = this.keyedQueues.get(key);
                  if (queue == null || queue.isEmpty()) {
                      throw new IllegalStateException(
                              "getNextElementKey returned key='"
                                      + key
                                      + "' but there are no elements available for the key. This violates the contract specified for getNextElementKey: "
                                      + this.toString());
                  }
  
                  final T e = queue.poll();
                  c.add(e);
  
                  count++;
              }
  
              this.size -= count;
  
              if (count > 0) {
                  this.notFull.signal();
              }
  
              return count;
          } finally {
              this.writeLock.unlock();
          }
      }