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

Comparing jsr166/src/jsr166x/ArrayDeque.java (file contents):
Revision 1.10 by jsr166, Sat Dec 29 23:55:19 2012 UTC vs.
Revision 1.11 by jsr166, Wed Jan 16 00:51:11 2013 UTC

# Line 16 | Line 16 | import java.io.*;
16   * {@link Stack} when used as a stack, and faster than {@link LinkedList}
17   * when used as a queue.
18   *
19 < * <p>Most <tt>ArrayDeque</tt> operations run in amortized constant time.
19 > * <p>Most {@code ArrayDeque} operations run in amortized constant time.
20   * Exceptions include {@link #remove(Object) remove}, {@link
21   * #removeFirstOccurrence removeFirstOccurrence}, {@link #removeLastOccurrence
22   * removeLastOccurrence}, {@link #contains contains }, {@link #iterator
23   * iterator.remove()}, and the bulk operations, all of which run in linear
24   * time.
25   *
26 < * <p>The iterators returned by this class's <tt>iterator</tt> method are
26 > * <p>The iterators returned by this class's {@code iterator} method are
27   * <i>fail-fast</i>: If the deque is modified at any time after the iterator
28   * is created, in any way except through the iterator's own remove method, the
29   * iterator will generally throw a {@link ConcurrentModificationException}.
# Line 34 | Line 34 | import java.io.*;
34   * <p>Note that the fail-fast behavior of an iterator cannot be guaranteed
35   * as it is, generally speaking, impossible to make any hard guarantees in the
36   * presence of unsynchronized concurrent modification.  Fail-fast iterators
37 < * throw <tt>ConcurrentModificationException</tt> on a best-effort basis.
37 > * throw {@code ConcurrentModificationException} on a best-effort basis.
38   * Therefore, it would be wrong to write a program that depended on this
39   * exception for its correctness: <i>the fail-fast behavior of iterators
40   * should be used only to detect bugs.</i>
# Line 188 | Line 188 | public class ArrayDeque<E> extends Abstr
188       * Inserts the specified element to the front this deque.
189       *
190       * @param e the element to insert
191 <     * @throws NullPointerException if <tt>e</tt> is null
191 >     * @throws NullPointerException if {@code e} is null
192       */
193      public void addFirst(E e) {
194          if (e == null)
# Line 204 | Line 204 | public class ArrayDeque<E> extends Abstr
204       * {@link #push}.
205       *
206       * @param e the element to insert
207 <     * @throws NullPointerException if <tt>e</tt> is null
207 >     * @throws NullPointerException if {@code e} is null
208       */
209      public void addLast(E e) {
210          if (e == null)
# Line 216 | Line 216 | public class ArrayDeque<E> extends Abstr
216  
217      /**
218       * Retrieves and removes the first element of this deque, or
219 <     * <tt>null</tt> if this deque is empty.
219 >     * {@code null} if this deque is empty.
220       *
221 <     * @return the first element of this deque, or <tt>null</tt> if
221 >     * @return the first element of this deque, or {@code null} if
222       *     this deque is empty
223       */
224      public E pollFirst() {
# Line 233 | Line 233 | public class ArrayDeque<E> extends Abstr
233  
234      /**
235       * Retrieves and removes the last element of this deque, or
236 <     * <tt>null</tt> if this deque is empty.
236 >     * {@code null} if this deque is empty.
237       *
238 <     * @return the last element of this deque, or <tt>null</tt> if
238 >     * @return the last element of this deque, or {@code null} if
239       *     this deque is empty
240       */
241      public E pollLast() {
# Line 252 | Line 252 | public class ArrayDeque<E> extends Abstr
252       * Inserts the specified element to the front this deque.
253       *
254       * @param e the element to insert
255 <     * @return <tt>true</tt> (as per the spec for {@link Deque#offerFirst})
256 <     * @throws NullPointerException if <tt>e</tt> is null
255 >     * @return {@code true} (as per the spec for {@link Deque#offerFirst})
256 >     * @throws NullPointerException if {@code e} is null
257       */
258      public boolean offerFirst(E e) {
259          addFirst(e);
# Line 264 | Line 264 | public class ArrayDeque<E> extends Abstr
264       * Inserts the specified element to the end this deque.
265       *
266       * @param e the element to insert
267 <     * @return <tt>true</tt> (as per the spec for {@link Deque#offerLast})
268 <     * @throws NullPointerException if <tt>e</tt> is null
267 >     * @return {@code true} (as per the spec for {@link Deque#offerLast})
268 >     * @throws NullPointerException if {@code e} is null
269       */
270      public boolean offerLast(E e) {
271          addLast(e);
# Line 274 | Line 274 | public class ArrayDeque<E> extends Abstr
274  
275      /**
276       * Retrieves and removes the first element of this deque.  This method
277 <     * differs from the <tt>pollFirst</tt> method in that it throws an
277 >     * differs from the {@code pollFirst} method in that it throws an
278       * exception if this deque is empty.
279       *
280       * @return the first element of this deque
# Line 289 | Line 289 | public class ArrayDeque<E> extends Abstr
289  
290      /**
291       * Retrieves and removes the last element of this deque.  This method
292 <     * differs from the <tt>pollLast</tt> method in that it throws an
292 >     * differs from the {@code pollLast} method in that it throws an
293       * exception if this deque is empty.
294       *
295       * @return the last element of this deque
# Line 304 | Line 304 | public class ArrayDeque<E> extends Abstr
304  
305      /**
306       * Retrieves, but does not remove, the first element of this deque,
307 <     * returning <tt>null</tt> if this deque is empty.
307 >     * returning {@code null} if this deque is empty.
308       *
309 <     * @return the first element of this deque, or <tt>null</tt> if
309 >     * @return the first element of this deque, or {@code null} if
310       *     this deque is empty
311       */
312      public E peekFirst() {
# Line 315 | Line 315 | public class ArrayDeque<E> extends Abstr
315  
316      /**
317       * Retrieves, but does not remove, the last element of this deque,
318 <     * returning <tt>null</tt> if this deque is empty.
318 >     * returning {@code null} if this deque is empty.
319       *
320 <     * @return the last element of this deque, or <tt>null</tt> if this deque
320 >     * @return the last element of this deque, or {@code null} if this deque
321       *     is empty
322       */
323      public E peekLast() {
# Line 326 | Line 326 | public class ArrayDeque<E> extends Abstr
326  
327      /**
328       * Retrieves, but does not remove, the first element of this
329 <     * deque.  This method differs from the <tt>peek</tt> method only
329 >     * deque.  This method differs from the {@code peek} method only
330       * in that it throws an exception if this deque is empty.
331       *
332       * @return the first element of this deque
# Line 341 | Line 341 | public class ArrayDeque<E> extends Abstr
341  
342      /**
343       * Retrieves, but does not remove, the last element of this
344 <     * deque.  This method differs from the <tt>peek</tt> method only
344 >     * deque.  This method differs from the {@code peek} method only
345       * in that it throws an exception if this deque is empty.
346       *
347       * @return the last element of this deque
# Line 360 | Line 360 | public class ArrayDeque<E> extends Abstr
360       * does not contain the element, it is unchanged.
361       *
362       * @param e element to be removed from this deque, if present
363 <     * @return <tt>true</tt> if the deque contained the specified element
363 >     * @return {@code true} if the deque contained the specified element
364       */
365      public boolean removeFirstOccurrence(Object e) {
366          if (e == null)
# Line 384 | Line 384 | public class ArrayDeque<E> extends Abstr
384       * does not contain the element, it is unchanged.
385       *
386       * @param e element to be removed from this deque, if present
387 <     * @return <tt>true</tt> if the deque contained the specified element
387 >     * @return {@code true} if the deque contained the specified element
388       */
389      public boolean removeLastOccurrence(Object e) {
390          if (e == null)
# Line 410 | Line 410 | public class ArrayDeque<E> extends Abstr
410       * <p>This method is equivalent to {@link #offerLast}.
411       *
412       * @param e the element to insert
413 <     * @return <tt>true</tt> (as per the spec for {@link Queue#offer})
414 <     * @throws NullPointerException if <tt>e</tt> is null
413 >     * @return {@code true} (as per the spec for {@link Queue#offer})
414 >     * @throws NullPointerException if {@code e} is null
415       */
416      public boolean offer(E e) {
417          return offerLast(e);
# Line 423 | Line 423 | public class ArrayDeque<E> extends Abstr
423       * <p>This method is equivalent to {@link #addLast}.
424       *
425       * @param e the element to insert
426 <     * @return <tt>true</tt> (as per the spec for {@link Collection#add})
427 <     * @throws NullPointerException if <tt>e</tt> is null
426 >     * @return {@code true} (as per the spec for {@link Collection#add})
427 >     * @throws NullPointerException if {@code e} is null
428       */
429      public boolean add(E e) {
430          addLast(e);
# Line 433 | Line 433 | public class ArrayDeque<E> extends Abstr
433  
434      /**
435       * Retrieves and removes the head of the queue represented by
436 <     * this deque, or <tt>null</tt> if this deque is empty.  In other words,
437 <     * retrieves and removes the first element of this deque, or <tt>null</tt>
436 >     * this deque, or {@code null} if this deque is empty.  In other words,
437 >     * retrieves and removes the first element of this deque, or {@code null}
438       * if this deque is empty.
439       *
440       * <p>This method is equivalent to {@link #pollFirst}.
441       *
442 <     * @return the first element of this deque, or <tt>null</tt> if
442 >     * @return the first element of this deque, or {@code null} if
443       *     this deque is empty
444       */
445      public E poll() {
# Line 448 | Line 448 | public class ArrayDeque<E> extends Abstr
448  
449      /**
450       * Retrieves and removes the head of the queue represented by this deque.
451 <     * This method differs from the <tt>poll</tt> method in that it throws an
451 >     * This method differs from the {@code poll} method in that it throws an
452       * exception if this deque is empty.
453       *
454       * <p>This method is equivalent to {@link #removeFirst}.
# Line 462 | Line 462 | public class ArrayDeque<E> extends Abstr
462  
463      /**
464       * Retrieves, but does not remove, the head of the queue represented by
465 <     * this deque, returning <tt>null</tt> if this deque is empty.
465 >     * this deque, returning {@code null} if this deque is empty.
466       *
467       * <p>This method is equivalent to {@link #peekFirst}
468       *
469       * @return the head of the queue represented by this deque, or
470 <     *     <tt>null</tt> if this deque is empty
470 >     *     {@code null} if this deque is empty
471       */
472      public E peek() {
473          return peekFirst();
# Line 475 | Line 475 | public class ArrayDeque<E> extends Abstr
475  
476      /**
477       * Retrieves, but does not remove, the head of the queue represented by
478 <     * this deque.  This method differs from the <tt>peek</tt> method only in
478 >     * this deque.  This method differs from the {@code peek} method only in
479       * that it throws an exception if this deque is empty.
480       *
481       * <p>This method is equivalent to {@link #getFirst}
# Line 496 | Line 496 | public class ArrayDeque<E> extends Abstr
496       * <p>This method is equivalent to {@link #addFirst}.
497       *
498       * @param e the element to push
499 <     * @throws NullPointerException if <tt>e</tt> is null
499 >     * @throws NullPointerException if {@code e} is null
500       */
501      public void push(E e) {
502          addFirst(e);
# Line 555 | Line 555 | public class ArrayDeque<E> extends Abstr
555      }
556  
557      /**
558 <     * Returns <tt>true</tt> if this collection contains no elements.
558 >     * Returns {@code true} if this collection contains no elements.
559       *
560 <     * @return <tt>true</tt> if this collection contains no elements
560 >     * @return {@code true} if this collection contains no elements
561       */
562      public boolean isEmpty() {
563          return head == tail;
# Line 569 | Line 569 | public class ArrayDeque<E> extends Abstr
569       * order that elements would be dequeued (via successive calls to
570       * {@link #remove} or popped (via successive calls to {@link #pop}).
571       *
572 <     * @return an <tt>Iterator</tt> over the elements in this deque
572 >     * @return an {@code Iterator} over the elements in this deque
573       */
574      public Iterator<E> iterator() {
575          return new DeqIterator();
# Line 621 | Line 621 | public class ArrayDeque<E> extends Abstr
621      }
622  
623      /**
624 <     * Returns <tt>true</tt> if this deque contains the specified
625 <     * element.  More formally, returns <tt>true</tt> if and only if this
626 <     * deque contains at least one element <tt>e</tt> such that
627 <     * <tt>e.equals(o)</tt>.
624 >     * Returns {@code true} if this deque contains the specified
625 >     * element.  More formally, returns {@code true} if and only if this
626 >     * deque contains at least one element {@code e} such that
627 >     * {@code e.equals(o)}.
628       *
629       * @param o object to be checked for containment in this deque
630 <     * @return <tt>true</tt> if this deque contains the specified element
630 >     * @return {@code true} if this deque contains the specified element
631       */
632      public boolean contains(Object o) {
633          if (o == null)
# Line 648 | Line 648 | public class ArrayDeque<E> extends Abstr
648       * This method is equivalent to {@link #removeFirstOccurrence}.
649       *
650       * @param e element to be removed from this deque, if present
651 <     * @return <tt>true</tt> if this deque contained the specified element
651 >     * @return {@code true} if this deque contained the specified element
652       */
653      public boolean remove(Object e) {
654          return removeFirstOccurrence(e);
# Line 691 | Line 691 | public class ArrayDeque<E> extends Abstr
691       *
692       * <p>If the deque fits in the specified array with room to spare (i.e.,
693       * the array has more elements than the deque), the element in the array
694 <     * immediately following the end of the collection is set to <tt>null</tt>.
694 >     * immediately following the end of the collection is set to {@code null}.
695       *
696       * @param a the array into which the elements of the deque are to
697       *          be stored, if it is big enough; otherwise, a new array of the
# Line 739 | Line 739 | public class ArrayDeque<E> extends Abstr
739      /**
740       * Serializes this deque.
741       *
742 <     * @serialData The current size (<tt>int</tt>) of the deque,
742 >     * @serialData The current size ({@code int}) of the deque,
743       * followed by all of its elements (each an object reference) in
744       * first-to-last order.
745       */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines