public int drainTo(Collection<? super E> c, int maxElements) {
        if (c == null)
            throw new NullPointerException();
        if (c == this)
            throw new IllegalArgumentException();
        if (maxElements <= 0)
            return 0;
        final ReentrantLock lock = this.lock;
        lock.lock();
        try {
            int n = Math.min(size, maxElements);
            for (int i = 0; i < n; i++) {
                c.add((E) queue[0]); // In this order, in case add() throws.
                dequeue();
            }
            return n;
        } finally {
            lock.unlock();
        }
    }
public int drainTo ( Collection < ? super E > c , int maxElements ) { if ( c == null ) throw new NullPointerException ( ) ; if ( c == this ) throw new IllegalArgumentException ( ) ; if ( maxElements <= 0 ) return 0 ; final ReentrantLock lock = this . lock ; lock . lock ( ) ; try { int n = Math . min ( size , maxElements ) ; for ( int i = 0 ; i < n ; i ++ ) { c . add ( ( E ) queue [ 0 ] ) ; dequeue ( ) ; } return n ; } finally { lock . unlock ( ) ; } }
@throws UnsupportedOperationException {@inheritDoc}
@throws ClassCastException            {@inheritDoc}
@throws NullPointerException          {@inheritDoc}
@throws IllegalArgumentException      {@inheritDoc}