public E addAndGetEvicted ( E e ) { checkNotNull ( e ) ; // check before removing if ( maxSize == 0 ) { return null ; } E evicted = null ; if ( size ( ) == maxSize ) { evicted = delegate . remove ( ) ; } delegate . add ( e ) ; return evicted ; }
Adds the given element to this queue . If the queue is currently full the element at the head of the queue is evicted to make room and returns the evicted element .