src/share/classes/java/util/ArrayDeque.java

Print this page

        

*** 119,128 **** --- 119,129 ---- /** * Allocate empty array to hold the given number of elements. * * @param numElements the number of elements to hold */ + @SuppressWarnings("unchecked") private void allocateElements(int numElements) { int initialCapacity = MIN_INITIAL_CAPACITY; // Find the best power of two to hold elements. // Tests "<=" because arrays aren't kept full. if (numElements >= initialCapacity) {
*** 150,163 **** 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 = (E[])a; head = 0; tail = n; } /** --- 151,165 ---- 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"); ! @SuppressWarnings("unchecked") ! E[] a = (E[]) new Object[newCapacity]; System.arraycopy(elements, p, a, 0, r); System.arraycopy(elements, 0, a, r, p); ! elements = a; head = 0; tail = n; } /**
*** 180,189 **** --- 182,192 ---- /** * Constructs an empty array deque with an initial capacity * sufficient to hold 16 elements. */ + @SuppressWarnings("unchecked") public ArrayDeque() { elements = (E[]) new Object[16]; } /**
*** 791,800 **** --- 794,804 ---- * @throws ArrayStoreException if the runtime type of the specified array * is not a supertype of the runtime type of every element in * this deque * @throws NullPointerException if the specified array is null */ + @SuppressWarnings("unchecked") public <T> T[] toArray(T[] a) { int size = size(); if (a.length < size) a = (T[])java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), size);