276 // terms of these.
277
278 /**
279 * Inserts the specified element at the front of this deque.
280 *
281 * @param e the element to add
282 * @throws NullPointerException if the specified element is null
283 */
284 public void addFirst(E e) {
285 if (e == null)
286 throw new NullPointerException();
287 final Object[] es = elements;
288 es[head = dec(head, es.length)] = e;
289 if (head == tail)
290 grow(1);
291 }
292
293 /**
294 * Inserts the specified element at the end of this deque.
295 *
296 * <p>This method is equivalent to {@link #add}.
297 *
298 * @param e the element to add
299 * @throws NullPointerException if the specified element is null
300 */
301 public void addLast(E e) {
302 if (e == null)
303 throw new NullPointerException();
304 final Object[] es = elements;
305 es[tail] = e;
306 if (head == (tail = inc(tail, es.length)))
307 grow(1);
308 }
309
310 /**
311 * Adds all of the elements in the specified collection at the end
312 * of this deque, as if by calling {@link #addLast} on each one,
313 * in the order that they are returned by the collection's iterator.
314 *
315 * @param c the elements to be inserted into this deque
316 * @return {@code true} if this deque changed as a result of the call
|
276 // terms of these.
277
278 /**
279 * Inserts the specified element at the front of this deque.
280 *
281 * @param e the element to add
282 * @throws NullPointerException if the specified element is null
283 */
284 public void addFirst(E e) {
285 if (e == null)
286 throw new NullPointerException();
287 final Object[] es = elements;
288 es[head = dec(head, es.length)] = e;
289 if (head == tail)
290 grow(1);
291 }
292
293 /**
294 * Inserts the specified element at the end of this deque.
295 *
296 * <p>This method is equivalent to {@link #add()}.
297 *
298 * @param e the element to add
299 * @throws NullPointerException if the specified element is null
300 */
301 public void addLast(E e) {
302 if (e == null)
303 throw new NullPointerException();
304 final Object[] es = elements;
305 es[tail] = e;
306 if (head == (tail = inc(tail, es.length)))
307 grow(1);
308 }
309
310 /**
311 * Adds all of the elements in the specified collection at the end
312 * of this deque, as if by calling {@link #addLast} on each one,
313 * in the order that they are returned by the collection's iterator.
314 *
315 * @param c the elements to be inserted into this deque
316 * @return {@code true} if this deque changed as a result of the call
|