--- jsr166/src/main/java/util/LinkedList.java 2005/06/18 01:56:01 1.36 +++ jsr166/src/main/java/util/LinkedList.java 2005/12/05 02:56:59 1.42 @@ -1,12 +1,12 @@ /* * %W% %E% * - * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ package java.util; -import java.util.*; // for javadoc +import java.util.*; // for javadoc (till 6280605 is fixed) /** * Linked list implementation of the List interface. Implements all @@ -26,18 +26,20 @@ import java.util.*; // for javadoc * list. Operations that index into the list will traverse the list from * the beginning or the end, whichever is closer to the specified index.

* - * Note that this implementation is not synchronized. If multiple - * threads access a list concurrently, and at least one of the threads - * modifies the list structurally, it must be synchronized - * externally. (A structural modification is any operation that adds or - * deletes one or more elements; merely setting the value of an element is not - * a structural modification.) This is typically accomplished by - * synchronizing on some object that naturally encapsulates the list. If no - * such object exists, the list should be "wrapped" using the - * Collections.synchronizedList method. This is best done at creation time, - * to prevent accidental unsynchronized access to the list:

- *     List list = Collections.synchronizedList(new LinkedList(...));
- * 
+ *

Note that this implementation is not synchronized. + * If multiple threads access a linked list concurrently, and at least + * one of the threads modifies the list structurally, it must be + * synchronized externally. (A structural modification is any operation + * that adds or deletes one or more elements; merely setting the value of + * an element is not a structural modification.) This is typically + * accomplished by synchronizing on some object that naturally + * encapsulates the list. + * + * If no such object exists, the list should be "wrapped" using the + * {@link Collections#synchronizedList Collections.synchronizedList} + * method. This is best done at creation time, to prevent accidental + * unsynchronized access to the list:

+ *   List list = Collections.synchronizedList(new LinkedList(...));
* *

The iterators returned by this class's iterator and * listIterator methods are fail-fast: if the list is @@ -66,7 +68,6 @@ import java.util.*; // for javadoc * @see List * @see ArrayList * @see Vector - * @see Collections#synchronizedList(List) * @since 1.2 * @param the type of elements held in this collection */ @@ -192,7 +193,7 @@ public class LinkedList *

This method is equivalent to {@link #addLast}. * * @param e element to be appended to this list - * @return true (as per the spec for {@link Collection#add}) + * @return true (as specified by {@link Collection#add}) */ public boolean add(E e) { addBefore(e, header); @@ -485,7 +486,7 @@ public class LinkedList * Adds the specified element as the tail (last element) of this list. * * @param e the element to add - * @return true (as per the spec for {@link Queue#offer}) + * @return true (as specified by {@link Queue#offer}) * @since 1.5 */ public boolean offer(E e) { @@ -497,7 +498,7 @@ public class LinkedList * Inserts the specified element at the front of this list. * * @param e the element to insert - * @return true (as per the spec for {@link Deque#offerFirst}) + * @return true (as specified by {@link Deque#offerFirst}) * @since 1.6 */ public boolean offerFirst(E e) { @@ -509,7 +510,7 @@ public class LinkedList * Inserts the specified element at the end of this list. * * @param e the element to insert - * @return true (as per the spec for {@link Deque#offerLast}) + * @return true (as specified by {@link Deque#offerLast}) * @since 1.6 */ public boolean offerLast(E e) { @@ -546,8 +547,8 @@ public class LinkedList } /** - * Retrieves and removes the first element of this list, or - * null if this list is empty. + * Retrieves and removes the first element of this list, + * or returns null if this list is empty. * * @return the first element of this list, or null if * this list is empty @@ -560,8 +561,8 @@ public class LinkedList } /** - * Retrieves and removes the last element of this list, or - * null if this list is empty. + * Retrieves and removes the last element of this list, + * or returns null if this list is empty. * * @return the last element of this list, or null if * this list is empty @@ -797,6 +798,24 @@ public class LinkedList return result; } + public Iterator descendingIterator() { + return new DescendingIterator(); + } + + /** Adapter to provide descending iterators via ListItr.previous */ + private class DescendingIterator implements Iterator { + final ListItr itr = new ListItr(size()); + public boolean hasNext() { + return itr.hasPrevious(); + } + public E next() { + return itr.previous(); + } + public void remove() { + itr.remove(); + } + } + /** * Returns a shallow copy of this LinkedList. (The elements * themselves are not cloned.)