private void doubleCapacity ( ) { assert head == tail ; int p = head ; int n = elements . length ; int r = n - p ; // number of elements to the right of p int newCapacity = n << 1 ; if ( newCapacity < 0 ) throw new IllegalStateException ( "Sorry, deque too big" ) ; Object [ ] a = new Object [ newCapacity ] ; System . arraycopy ( elements , p , a , 0 , r ) ; System . arraycopy ( elements , 0 , a , r , p ) ; elements = a ; head = 0 ; tail = n ; }
Doubles the capacity of this deque . Call only when full i . e . when head and tail have wrapped around to become equal .