--- jsr166/src/main/java/util/LinkedList.java 2004/11/21 01:40:39 1.16 +++ jsr166/src/main/java/util/LinkedList.java 2004/12/28 12:14:07 1.17 @@ -5,7 +5,7 @@ * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ -package java.util; +package java.util; /** * Linked list implementation of the List interface. Implements all @@ -14,14 +14,11 @@ package java.util; * the LinkedList class provides uniformly named methods to * get, remove and insert an element at the * beginning and end of the list. These operations allow linked lists to be - * used as a stack, queue, or double-ended queue (deque).
+ * used as a stack, queue, or double-ended queue ({@link Deque}).
* - * The class implements the Queue interface, providing + * The class implements the Deque interface, providing * first-in-first-out queue operations for add, - * poll, etc. Other stack and deque operations could be - * easily recast in terms of the standard list operations. They're - * included here primarily for convenience, though they may run - * slightly faster than the equivalent List operations.
+ * poll, along with other stack and deque operations.
*
* All of the operations perform as could be expected for a doubly-linked
* list. Operations that index into the list will traverse the list from
@@ -73,7 +70,7 @@ package java.util;
public class LinkedList This method is equivalent to {@link #addFirst}.
+ *
+ * @param e the element to push
+ * @since 1.6
+ */
+ public void push(E e) {
+ addFirst(e);
+ }
+
+ /**
+ * Pops an element from the stack represented by this deque. In other
+ * words, removes and returns the the first element of this deque.
+ *
+ * This method is equivalent to {@link #removeFirst()}.
+ *
+ * @return the element at the front of this deque (which is the top
+ * of the stack represented by this deque)
+ * @throws NoSuchElementException if this deque is empty
+ * @since 1.6
+ */
+ public E pop() {
+ return removeFirst();
+ }
+
+ /**
+ * Removes the first occurrence of the specified element in this
+ * deque (when traversing the deque from head to tail). If the deque
+ * does not contain the element, it is unchanged.
+ *
+ * @param e element to be removed from this deque, if present
+ * @return true if the deque contained the specified element
+ * @since 1.6
+ */
+ public boolean removeFirstOccurrence(Object e) {
+ return remove(e);
+ }
+
+ /**
+ * Removes the last occurrence of the specified element in this
+ * deque (when traversing the deque from head to tail). If the deque
+ * does not contain the element, it is unchanged.
+ *
+ * @param o element to be removed from this deque, if present
+ * @return true if the deque contained the specified element
+ * @since 1.6
+ */
+ public boolean removeLastOccurrence(Object o) {
+ if (o==null) {
+ for (Entry e = header.previous; e != header; e = e.previous) {
+ if (e.element==null) {
+ remove(e);
+ return true;
+ }
+ }
+ } else {
+ for (Entry e = header.previous; e != header; e = e.previous) {
+ if (o.equals(e.element)) {
+ remove(e);
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
/**
* Returns a list-iterator of the elements in this list (in proper
* sequence), starting at the specified position in the list.