public int drainTo(Collection<? super E> c, int maxElements) {
    if (c == null)
      throw new NullPointerException();
    if (c == this)
      throw new IllegalArgumentException();
    lock.lock();
    try {
      int n = 0;
      for (Iterator<E> it = list.iterator(); n < maxElements && it.hasNext();) {
        E e = it.next();
        c.add(e);
        it.remove();
        ++n;
      }

      notFull.signalAll();
      return n;
    } finally {
      lock.unlock();
    }
  }
@throws UnsupportedOperationException {@inheritDoc}
@throws ClassCastException            {@inheritDoc}
@throws NullPointerException          {@inheritDoc}
@throws IllegalArgumentException      {@inheritDoc}
llap-server/src/java/org/apache/hadoop/hive/llap/daemon/impl/PriorityBlockingDeque.java