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.27 by jsr166, Sat May 14 02:19:00 2005 UTC vs.
Revision 1.30 by jsr166, Tue May 17 06:36:47 2005 UTC

# Line 165 | Line 165 | public class LinkedList<E>
165      /**
166       * Returns <tt>true</tt> if this list contains the specified element.
167       * More formally, returns <tt>true</tt> if and only if this list contains
168 <     * at least one element <tt>e</tt> such that <tt>(o==null ? e==null
169 <     * : o.equals(e))</tt>.
168 >     * at least one element <tt>e</tt> such that
169 >     * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
170       *
171       * @param o element whose presence in this list is to be tested
172       * @return <tt>true</tt> if this list contains the specified element
# Line 196 | Line 196 | public class LinkedList<E>
196      }
197  
198      /**
199 <     * Removes the first occurrence of the specified element in this list.  If
200 <     * the list does not contain the element, it is unchanged.  More formally,
201 <     * removes the element with the lowest index <tt>i</tt> such that
202 <     * <tt>(o==null ? get(i)==null : o.equals(get(i)))</tt> (if such an
203 <     * element exists).
199 >     * Removes the first occurrence of the specified element from this list,
200 >     * if it is present.  If this list does not contain the element, it is
201 >     * unchanged.  More formally, removes the element with the lowest index
202 >     * <tt>i</tt> such that
203 >     * <tt>(o==null&nbsp;?&nbsp;get(i)==null&nbsp;:&nbsp;o.equals(get(i)))</tt>
204 >     * (if such an element exists).  Returns <tt>true</tt> if this list
205 >     * contained the specified element (or equivalently, if this list
206 >     * changed as a result of the call).
207       *
208       * @param o element to be removed from this list, if present
209 <     * @return <tt>true</tt> if the list contained the specified element
209 >     * @return <tt>true</tt> if this list contained the specified element
210       */
211      public boolean remove(Object o) {
212          if (o==null) {
# Line 252 | Line 255 | public class LinkedList<E>
255       *              from the specified collection
256       * @param c elements to be inserted into this list
257       * @return <tt>true</tt> if this list changed as a result of the call
258 <     * @throws IndexOutOfBoundsException if the index is out of range
256 <     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
258 >     * @throws IndexOutOfBoundsException {@inheritDoc}
259       * @throws NullPointerException if the specified collection is null
260       */
261      public boolean addAll(int index, Collection<? extends E> c) {
# Line 301 | Line 303 | public class LinkedList<E>
303      /**
304       * Returns the element at the specified position in this list.
305       *
306 <     * @param index index of element to return
306 >     * @param index index of the element to return
307       * @return the element at the specified position in this list
308 <     * @throws IndexOutOfBoundsException if the index is out of range
307 <     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
308 >     * @throws IndexOutOfBoundsException {@inheritDoc}
309       */
310      public E get(int index) {
311          return entry(index).element;
# Line 314 | Line 315 | public class LinkedList<E>
315       * Replaces the element at the specified position in this list with the
316       * specified element.
317       *
318 <     * @param index index of element to replace
318 >     * @param index index of the element to replace
319       * @param element element to be stored at the specified position
320       * @return the element previously at the specified position
321 <     * @throws IndexOutOfBoundsException if the index is out of range
321 <     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
321 >     * @throws IndexOutOfBoundsException {@inheritDoc}
322       */
323      public E set(int index, E element) {
324          Entry<E> e = entry(index);
# Line 334 | Line 334 | public class LinkedList<E>
334       *
335       * @param index index at which the specified element is to be inserted
336       * @param element element to be inserted
337 <     *
338 <     * @throws IndexOutOfBoundsException if the index is out of range
339 <     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
337 >     * @throws IndexOutOfBoundsException {@inheritDoc}
338       */
339      public void add(int index, E element) {
340          addBefore(element, (index==size ? header : entry(index)));
# Line 349 | Line 347 | public class LinkedList<E>
347       *
348       * @param index the index of the element to be removed
349       * @return the element previously at the specified position
350 <     *
353 <     * @throws IndexOutOfBoundsException if the index is out of range
354 <     *         (<tt>index &lt; 0 || index &gt; size()</tt>)
350 >     * @throws IndexOutOfBoundsException {@inheritDoc}
351       */
352      public E remove(int index) {
353          return remove(entry(index));
# Line 379 | 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
391 <     *         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 409 | 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
421 <     *         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 524 | Line 518 | public class LinkedList<E>
518       * or returns <tt>null</tt> if this list is empty.
519       *
520       * @return the first element of this list, or <tt>null</tt>
521 <     *         if this list is empty.
521 >     *         if this list is empty
522       * @since 1.6
523       */
524      public E peekFirst() {
# Line 538 | Line 532 | public class LinkedList<E>
532       * or returns <tt>null</tt> if this list is empty.
533       *
534       * @return the last element of this list, or <tt>null</tt>
535 <     *         if this list is empty.
535 >     *         if this list is empty
536       * @since 1.6
537       */
538      public E peekLast() {
# Line 659 | Line 653 | public class LinkedList<E>
653       * time in the future.
654       *
655       * @param index index of the first element to be returned from the
656 <     *              list-iterator (by a call to <tt>next</tt>).
656 >     *              list-iterator (by a call to <tt>next</tt>)
657       * @return a ListIterator of the elements in this list (in proper
658 <     *         sequence), starting at the specified position in the list.
659 <     * @throws IndexOutOfBoundsException if the index is out of range
666 <     *         (<tt>index &lt; 0 || index &gt; size()</tt>).
658 >     *         sequence), starting at the specified position in the list
659 >     * @throws IndexOutOfBoundsException {@inheritDoc}
660       * @see List#listIterator(int)
661       */
662      public ListIterator<E> listIterator(int index) {
# Line 829 | 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 844 | 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