public E insert ( E element ) { E evicted = null ; if ( size ( ) >= capacity ) { if ( evictPolicy == EvictPolicy . REJECT_NEW ) { // reject the new element return element ; } // Evict first, so we do not need to resize evicted = evict ( ) ; } deque . offerLast ( element ) ; return evicted ; }
Inserts an element into the deque and returns the one that had to be evicted in case of a capacity violation .