163 /** Capacity calculation for edge conditions, especially overflow. */
164 private int newCapacity(int needed, int jump) {
165 final int oldCapacity = elements.length, minCapacity;
166 if ((minCapacity = oldCapacity + needed) - MAX_ARRAY_SIZE > 0) {
167 if (minCapacity < 0)
168 throw new IllegalStateException("Sorry, deque too big");
169 return Integer.MAX_VALUE;
170 }
171 if (needed > jump)
172 return minCapacity;
173 return (oldCapacity + jump - MAX_ARRAY_SIZE < 0)
174 ? oldCapacity + jump
175 : MAX_ARRAY_SIZE;
176 }
177
178 /**
179 * Constructs an empty array deque with an initial capacity
180 * sufficient to hold 16 elements.
181 */
182 public ArrayDeque() {
183 elements = new Object[16];
184 }
185
186 /**
187 * Constructs an empty array deque with an initial capacity
188 * sufficient to hold the specified number of elements.
189 *
190 * @param numElements lower bound on initial capacity of the deque
191 */
192 public ArrayDeque(int numElements) {
193 elements =
194 new Object[(numElements < 1) ? 1 :
195 (numElements == Integer.MAX_VALUE) ? Integer.MAX_VALUE :
196 numElements + 1];
197 }
198
199 /**
200 * Constructs a deque containing the elements of the specified
201 * collection, in the order they are returned by the collection's
202 * iterator. (The first element returned by the collection's
203 * iterator becomes the first element, or <i>front</i> of the
|
163 /** Capacity calculation for edge conditions, especially overflow. */
164 private int newCapacity(int needed, int jump) {
165 final int oldCapacity = elements.length, minCapacity;
166 if ((minCapacity = oldCapacity + needed) - MAX_ARRAY_SIZE > 0) {
167 if (minCapacity < 0)
168 throw new IllegalStateException("Sorry, deque too big");
169 return Integer.MAX_VALUE;
170 }
171 if (needed > jump)
172 return minCapacity;
173 return (oldCapacity + jump - MAX_ARRAY_SIZE < 0)
174 ? oldCapacity + jump
175 : MAX_ARRAY_SIZE;
176 }
177
178 /**
179 * Constructs an empty array deque with an initial capacity
180 * sufficient to hold 16 elements.
181 */
182 public ArrayDeque() {
183 // One extra slot for a null element at the tail
184 elements = new Object[16 + 1];
185 }
186
187 /**
188 * Constructs an empty array deque with an initial capacity
189 * sufficient to hold the specified number of elements.
190 *
191 * @param numElements lower bound on initial capacity of the deque
192 */
193 public ArrayDeque(int numElements) {
194 elements =
195 new Object[(numElements < 1) ? 1 :
196 (numElements == Integer.MAX_VALUE) ? Integer.MAX_VALUE :
197 numElements + 1];
198 }
199
200 /**
201 * Constructs a deque containing the elements of the specified
202 * collection, in the order they are returned by the collection's
203 * iterator. (The first element returned by the collection's
204 * iterator becomes the first element, or <i>front</i> of the
|