/** * Returns an Iterable over all results added so far, but * atomically clears the structure as well. * The returned iterable will be the only entry point to * read the previously appended data. * @return an Iterable, or null if there is no data. */ public Iterable<T> drainToDetachedIterable() { final Node<T> head = drainHead(); if ( head != null ) { return new DetachedNodeIterable<T>( head ); } else { //The choice to return null rather than an empty iterator //allows the client to not need an isEmpty() method, which would //need a different level of lock granularity. return null; } }
/** * Returns an Iterable over all results added so far, but * atomically clears the structure as well. * The returned iterable will be the only entry point to * read the previously appended data. * @return an Iterable, or null if there is no data. */ public Iterable<T> drainToDetachedIterable() { final Node<T> head = drainHead(); if ( head != null ) { return new DetachedNodeIterable<T>( head ); } else { //The choice to return null rather than an empty iterator //allows the client to not need an isEmpty() method, which would //need a different level of lock granularity. return null; } }