nl_tokens: Removes at most the given number of available elements from this queue and adds them into the given collection . A failure encountered while attempting to <tt > add< / tt > elements to collection <tt > c< / tt > may result in elements being in neither either or both collections when the associated exception is thrown . Attempts to drain a queue to itself result in <tt > IllegalArgumentException< / tt > . Further the behavior of this operation is undefined if the specified collection is modified while the operation is in progress .
pl_tokens: public int drainTo ( Collection < ? super E > collection , int maxElements ) { if ( collection == null ) { throw new IllegalArgumentException ( "The 'collection' parameter may not be null." ) ; } if ( collection == this ) { throw new IllegalArgumentException ( "The 'collection' parameter may not be this object." ) ; } // final Queue<E> items = this.buffer; ReentrantLock lock = this . lock ; lock . lock ( ) ; try { int n = 0 ; for ( int <mask> = ( ( maxElements >= count ) || ( maxElements < 0 ) ) ? count : maxElements ; n < max ; n ++ ) { // Take items from the queue, do unblock the producers, but don't send not full signals yet. collection . add ( extract ( true , false ) . getElement ( ) ) ; } if ( n > 0 ) { // count -= n; notFull . signalAll ( ) ; } return n ; } finally { lock . unlock ( ) ; } }