ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/LinkedList.java
(Generate patch)

Comparing jsr166/src/main/java/util/LinkedList.java (file contents):
Revision 1.28 by jsr166, Mon May 16 05:17:07 2005 UTC vs.
Revision 1.34 by dl, Wed May 25 14:05:06 2005 UTC

# Line 232 | Line 232 | public class LinkedList<E>
232       * this list, in the order that they are returned by the specified
233       * collection's iterator.  The behavior of this operation is undefined if
234       * the specified collection is modified while the operation is in
235 <     * progress.  (This implies that the behavior of this call is undefined if
236 <     * the specified Collection is this list, and this list is nonempty.)
235 >     * progress.  (Note that this will occur if the specified collection is
236 >     * this list, and it's nonempty.)
237       *
238 <     * @param c the elements to be inserted into this list
238 >     * @param c collection containing elements to be added to this list
239       * @return <tt>true</tt> if this list changed as a result of the call
240       * @throws NullPointerException if the specified collection is null
241       */
# Line 253 | Line 253 | public class LinkedList<E>
253       *
254       * @param index index at which to insert the first element
255       *              from the specified collection
256 <     * @param c elements to be inserted into this list
256 >     * @param c collection containing elements to be added to this list
257       * @return <tt>true</tt> if this list changed as a result of the call
258       * @throws IndexOutOfBoundsException {@inheritDoc}
259       * @throws NullPointerException if the specified collection is null
# Line 375 | Line 375 | public class LinkedList<E>
375      // Search Operations
376  
377      /**
378 <     * Returns the index in this list of the first occurrence of the
379 <     * specified element, or -1 if the List does not contain this
380 <     * element.  More formally, returns the lowest index i such that
381 <     * <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>, or -1 if
382 <     * there is no such index.
378 >     * Returns the index of the first occurrence of the specified element
379 >     * in this list, or -1 if this list does not contain the element.
380 >     * More formally, returns the lowest index <tt>i</tt> such that
381 >     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
382 >     * or -1 if there is no such index.
383       *
384       * @param o element to search for
385 <     * @return the index in this list of the first occurrence of the
386 <     *         specified element, or -1 if the list does not contain this
387 <     *         element
385 >     * @return the index of the first occurrence of the specified element in
386 >     *         this list, or -1 if this list does not contain the element
387       */
388      public int indexOf(Object o) {
389          int index = 0;
# Line 405 | Line 404 | public class LinkedList<E>
404      }
405  
406      /**
407 <     * Returns the index in this list of the last occurrence of the
408 <     * specified element, or -1 if the list does not contain this
409 <     * element.  More formally, returns the highest index i such that
410 <     * <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt>, or -1 if
411 <     * there is no such index.
407 >     * Returns the index of the last occurrence of the specified element
408 >     * in this list, or -1 if this list does not contain the element.
409 >     * More formally, returns the highest index <tt>i</tt> such that
410 >     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>,
411 >     * or -1 if there is no such index.
412       *
413       * @param o element to search for
414 <     * @return the index in this list of the last occurrence of the
415 <     *         specified element, or -1 if the list does not contain this
417 <     *         element
414 >     * @return the index of the last occurrence of the specified element in
415 >     *         this list, or -1 if this list does not contain the element
416       */
417      public int lastIndexOf(Object o) {
418          int index = size;
# Line 623 | Line 621 | public class LinkedList<E>
621       */
622      public boolean removeLastOccurrence(Object o) {
623          if (o==null) {
624 <            for (Entry e = header.previous; e != header; e = e.previous) {
624 >            for (Entry<E> e = header.previous; e != header; e = e.previous) {
625                  if (e.element==null) {
626                      remove(e);
627                      return true;
628                  }
629              }
630          } else {
631 <            for (Entry e = header.previous; e != header; e = e.previous) {
631 >            for (Entry<E> e = header.previous; e != header; e = e.previous) {
632                  if (o.equals(e.element)) {
633                      remove(e);
634                      return true;
# Line 824 | Line 822 | public class LinkedList<E>
822  
823      /**
824       * Returns an array containing all of the elements in this list
825 <     * in the correct order.
825 >     * in proper sequence (from first to last element).
826 >     *
827 >     * <p>The returned array will be "safe" in that no references to it are
828 >     * maintained by this list.  (In other words, this method must allocate
829 >     * a new array).  The caller is thus free to modify the returned array.
830 >     *
831 >     * <p>This method acts as bridge between array-based and collection-based
832 >     * APIs.
833       *
834       * @return an array containing all of the elements in this list
835 <     *         in the correct order
835 >     *         in proper sequence
836       */
837      public Object[] toArray() {
838          Object[] result = new Object[size];
# Line 839 | Line 844 | public class LinkedList<E>
844  
845      /**
846       * Returns an array containing all of the elements in this list in
847 <     * the correct order; the runtime type of the returned array is that of
848 <     * the specified array.  If the list fits in the specified array, it
849 <     * is returned therein.  Otherwise, a new array is allocated with the
850 <     * runtime type of the specified array and the size of this list.<p>
851 <     *
852 <     * If the list fits in the specified array with room to spare
853 <     * (i.e., the array has more elements than the list),
854 <     * the element in the array immediately following the end of the
855 <     * collection is set to null.  This is useful in determining the length
856 <     * of the list <i>only</i> if the caller knows that the list
857 <     * does not contain any null elements.
847 >     * proper sequence (from first to last element); the runtime type of
848 >     * the returned array is that of the specified array.  If the list fits
849 >     * in the specified array, it is returned therein.  Otherwise, a new
850 >     * array is allocated with the runtime type of the specified array and
851 >     * the size of this list.
852 >     *
853 >     * <p>If the list fits in the specified array with room to spare (i.e.,
854 >     * the array has more elements than the list), the element in the array
855 >     * immediately following the end of the list is set to <tt>null</tt>.
856 >     * (This is useful in determining the length of the list <i>only</i> if
857 >     * the caller knows that the list does not contain any null elements.)
858 >     *
859 >     * <p>Like the {@link #toArray()} method, this method acts as bridge between
860 >     * array-based and collection-based APIs.  Further, this method allows
861 >     * precise control over the runtime type of the output array, and may,
862 >     * under certain circumstances, be used to save allocation costs.
863 >     *
864 >     * <p>Suppose <tt>x</tt> is a list known to contain only strings.
865 >     * The following code can be used to dump the list into a newly
866 >     * allocated array of <tt>String</tt>:
867 >     *
868 >     * <pre>
869 >     *     String[] y = x.toArray(new String[0]);</pre>
870 >     *
871 >     * Note that <tt>toArray(new Object[0])</tt> is identical in function to
872 >     * <tt>toArray()</tt>.
873       *
874       * @param a the array into which the elements of the list are to
875       *          be stored, if it is big enough; otherwise, a new array of the
876       *          same runtime type is allocated for this purpose.
877       * @return an array containing the elements of the list
878 <     * @throws ArrayStoreException if the runtime type of a is not a
879 <     *         supertype of the runtime type of every element in this list
878 >     * @throws ArrayStoreException if the runtime type of the specified array
879 >     *         is not a supertype of the runtime type of every element in
880 >     *         this list
881       * @throws NullPointerException if the specified array is null
882       */
883      public <T> T[] toArray(T[] a) {

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines