1 |
|
/* |
2 |
< |
* @(#)LinkedList.java 1.53 03/06/22 |
2 |
> |
* %W% %E% |
3 |
|
* |
4 |
|
* Copyright 2003 Sun Microsystems, Inc. All rights reserved. |
5 |
|
* SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. |
25 |
|
* |
26 |
|
* All of the operations perform as could be expected for a doubly-linked |
27 |
|
* list. Operations that index into the list will traverse the list from |
28 |
< |
* the begining or the end, whichever is closer to the specified index.<p> |
28 |
> |
* the beginning or the end, whichever is closer to the specified index.<p> |
29 |
|
* |
30 |
|
* <b>Note that this implementation is not synchronized.</b> If multiple |
31 |
|
* threads access a list concurrently, and at least one of the threads |
62 |
|
* Java Collections Framework</a>. |
63 |
|
* |
64 |
|
* @author Josh Bloch |
65 |
< |
* @version 1.53, 06/22/03 |
65 |
> |
* @version %I%, %G% |
66 |
|
* @see List |
67 |
|
* @see ArrayList |
68 |
|
* @see Vector |
69 |
|
* @see Collections#synchronizedList(List) |
70 |
|
* @since 1.2 |
71 |
+ |
* @param <E> the type of elements held in this collection |
72 |
|
*/ |
73 |
|
|
74 |
|
public class LinkedList<E> |
443 |
|
// Queue operations. |
444 |
|
|
445 |
|
/** |
446 |
< |
* Retrieves, but does not remove, the head (first element) of this list.. |
446 |
> |
* Retrieves, but does not remove, the head (first element) of this list. |
447 |
|
* @return the head of this queue, or <tt>null</tt> if this queue is empty. |
448 |
+ |
* @since 1.5 |
449 |
|
*/ |
450 |
|
public E peek() { |
451 |
|
if (size==0) |
454 |
|
} |
455 |
|
|
456 |
|
/** |
457 |
< |
* Retrieves, but does not remove, the head (first element) of this list.. |
457 |
> |
* Retrieves, but does not remove, the head (first element) of this list. |
458 |
|
* @return the head of this queue. |
459 |
|
* @throws NoSuchElementException if this queue is empty. |
460 |
+ |
* @since 1.5 |
461 |
|
*/ |
462 |
|
public E element() { |
463 |
|
return getFirst(); |
464 |
|
} |
465 |
|
|
466 |
|
/** |
467 |
< |
* Retrieves and removes the head (first element) of this list.. |
467 |
> |
* Retrieves and removes the head (first element) of this list. |
468 |
|
* @return the head of this queue, or <tt>null</tt> if this queue is empty. |
469 |
+ |
* @since 1.5 |
470 |
|
*/ |
471 |
|
public E poll() { |
472 |
|
if (size==0) |
475 |
|
} |
476 |
|
|
477 |
|
/** |
478 |
< |
* Retrieves and removes the head (first element) of this list.. |
478 |
> |
* Retrieves and removes the head (first element) of this list. |
479 |
|
* @return the head of this queue. |
480 |
|
* @throws NoSuchElementException if this queue is empty. |
481 |
+ |
* @since 1.5 |
482 |
|
*/ |
483 |
|
public E remove() { |
484 |
|
return removeFirst(); |
487 |
|
/** |
488 |
|
* Adds the specified element as the tail (last element) of this list. |
489 |
|
* |
490 |
< |
* @param o the element to add. |
490 |
> |
* @param x the element to add. |
491 |
|
* @return <tt>true</tt> (as per the general contract of |
492 |
|
* <tt>Queue.offer</tt>) |
493 |
+ |
* @since 1.5 |
494 |
|
*/ |
495 |
|
public boolean offer(E x) { |
496 |
|
return add(x); |