[cvs] / jsr166 / src / main / java / util / Deque.java Repository:
ViewVC logotype

Diff of /jsr166/src/main/java/util/Deque.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.21, Sun Oct 21 06:40:20 2012 UTC revision 1.22, Wed Jan 16 01:59:47 2013 UTC
# Line 9  Line 9 
9  /**  /**
10   * A linear collection that supports element insertion and removal at   * A linear collection that supports element insertion and removal at
11   * both ends.  The name <i>deque</i> is short for "double ended queue"   * both ends.  The name <i>deque</i> is short for "double ended queue"
12   * and is usually pronounced "deck".  Most <tt>Deque</tt>   * and is usually pronounced "deck".  Most {@code Deque}
13   * implementations place no fixed limits on the number of elements   * implementations place no fixed limits on the number of elements
14   * they may contain, but this interface supports capacity-restricted   * they may contain, but this interface supports capacity-restricted
15   * deques as well as those with no fixed size limit.   * deques as well as those with no fixed size limit.
# Line 18  Line 18 
18   * ends of the deque.  Methods are provided to insert, remove, and   * ends of the deque.  Methods are provided to insert, remove, and
19   * examine the element.  Each of these methods exists in two forms:   * examine the element.  Each of these methods exists in two forms:
20   * one throws an exception if the operation fails, the other returns a   * one throws an exception if the operation fails, the other returns a
21   * special value (either <tt>null</tt> or <tt>false</tt>, depending on   * special value (either {@code null} or {@code false}, depending on
22   * the operation).  The latter form of the insert operation is   * the operation).  The latter form of the insert operation is
23   * designed specifically for use with capacity-restricted   * designed specifically for use with capacity-restricted
24   * <tt>Deque</tt> implementations; in most implementations, insert   * {@code Deque} implementations; in most implementations, insert
25   * operations cannot fail.   * operations cannot fail.
26   *   *
27   * <p>The twelve methods described above are summarized in the   * <p>The twelve methods described above are summarized in the
# Line 67  Line 67 
67   * <p>This interface extends the {@link Queue} interface.  When a deque is   * <p>This interface extends the {@link Queue} interface.  When a deque is
68   * used as a queue, FIFO (First-In-First-Out) behavior results.  Elements are   * used as a queue, FIFO (First-In-First-Out) behavior results.  Elements are
69   * added at the end of the deque and removed from the beginning.  The methods   * added at the end of the deque and removed from the beginning.  The methods
70   * inherited from the <tt>Queue</tt> interface are precisely equivalent to   * inherited from the {@code Queue} interface are precisely equivalent to
71   * <tt>Deque</tt> methods as indicated in the following table:   * {@code Deque} methods as indicated in the following table:
72   *   *
73   * <p>   * <p>
74   * <table BORDER CELLPADDING=3 CELLSPACING=1>   * <table BORDER CELLPADDING=3 CELLSPACING=1>
75   *  <tr>   *  <tr>
76   *    <td ALIGN=CENTER> <b><tt>Queue</tt> Method</b></td>   *    <td ALIGN=CENTER> <b>{@code Queue} Method</b></td>
77   *    <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>   *    <td ALIGN=CENTER> <b>Equivalent {@code Deque} Method</b></td>
78   *  </tr>   *  </tr>
79   *  <tr>   *  <tr>
80   *    <td>{@link java.util.Queue#add add(e)}</td>   *    <td>{@link java.util.Queue#add add(e)}</td>
# Line 106  Line 106 
106   * interface should be used in preference to the legacy {@link Stack} class.   * interface should be used in preference to the legacy {@link Stack} class.
107   * When a deque is used as a stack, elements are pushed and popped from the   * When a deque is used as a stack, elements are pushed and popped from the
108   * beginning of the deque.  Stack methods are precisely equivalent to   * beginning of the deque.  Stack methods are precisely equivalent to
109   * <tt>Deque</tt> methods as indicated in the table below:   * {@code Deque} methods as indicated in the table below:
110   *   *
111   * <p>   * <p>
112   * <table BORDER CELLPADDING=3 CELLSPACING=1>   * <table BORDER CELLPADDING=3 CELLSPACING=1>
113   *  <tr>   *  <tr>
114   *    <td ALIGN=CENTER> <b>Stack Method</b></td>   *    <td ALIGN=CENTER> <b>Stack Method</b></td>
115   *    <td ALIGN=CENTER> <b>Equivalent <tt>Deque</tt> Method</b></td>   *    <td ALIGN=CENTER> <b>Equivalent {@code Deque} Method</b></td>
116   *  </tr>   *  </tr>
117   *  <tr>   *  <tr>
118   *    <td>{@link #push push(e)}</td>   *    <td>{@link #push push(e)}</td>
# Line 139  Line 139 
139   * <p>Unlike the {@link List} interface, this interface does not   * <p>Unlike the {@link List} interface, this interface does not
140   * provide support for indexed access to elements.   * provide support for indexed access to elements.
141   *   *
142   * <p>While <tt>Deque</tt> implementations are not strictly required   * <p>While {@code Deque} implementations are not strictly required
143   * to prohibit the insertion of null elements, they are strongly   * to prohibit the insertion of null elements, they are strongly
144   * encouraged to do so.  Users of any <tt>Deque</tt> implementations   * encouraged to do so.  Users of any {@code Deque} implementations
145   * that do allow null elements are strongly encouraged <i>not</i> to   * that do allow null elements are strongly encouraged <i>not</i> to
146   * take advantage of the ability to insert nulls.  This is so because   * take advantage of the ability to insert nulls.  This is so because
147   * <tt>null</tt> is used as a special return value by various methods   * {@code null} is used as a special return value by various methods
148   * to indicated that the deque is empty.   * to indicated that the deque is empty.
149   *   *
150   * <p><tt>Deque</tt> implementations generally do not define   * <p>{@code Deque} implementations generally do not define
151   * element-based versions of the <tt>equals</tt> and <tt>hashCode</tt>   * element-based versions of the {@code equals} and {@code hashCode}
152   * methods, but instead inherit the identity-based versions from class   * methods, but instead inherit the identity-based versions from class
153   * <tt>Object</tt>.   * {@code Object}.
154   *   *
155   * <p>This interface is a member of the <a   * <p>This interface is a member of the <a
156   * href="{@docRoot}/../technotes/guides/collections/index.html"> Java Collections   * href="{@docRoot}/../technotes/guides/collections/index.html"> Java Collections
# Line 207  Line 207 
207       * which can fail to insert an element only by throwing an exception.       * which can fail to insert an element only by throwing an exception.
208       *       *
209       * @param e the element to add       * @param e the element to add
210       * @return <tt>true</tt> if the element was added to this deque, else       * @return {@code true} if the element was added to this deque, else
211       *         <tt>false</tt>       *         {@code false}
212       * @throws ClassCastException if the class of the specified element       * @throws ClassCastException if the class of the specified element
213       *         prevents it from being added to this deque       *         prevents it from being added to this deque
214       * @throws NullPointerException if the specified element is null and this       * @throws NullPointerException if the specified element is null and this
# Line 225  Line 225 
225       * which can fail to insert an element only by throwing an exception.       * which can fail to insert an element only by throwing an exception.
226       *       *
227       * @param e the element to add       * @param e the element to add
228       * @return <tt>true</tt> if the element was added to this deque, else       * @return {@code true} if the element was added to this deque, else
229       *         <tt>false</tt>       *         {@code false}
230       * @throws ClassCastException if the class of the specified element       * @throws ClassCastException if the class of the specified element
231       *         prevents it from being added to this deque       *         prevents it from being added to this deque
232       * @throws NullPointerException if the specified element is null and this       * @throws NullPointerException if the specified element is null and this
# Line 258  Line 258 
258    
259      /**      /**
260       * Retrieves and removes the first element of this deque,       * Retrieves and removes the first element of this deque,
261       * or returns <tt>null</tt> if this deque is empty.       * or returns {@code null} if this deque is empty.
262       *       *
263       * @return the head of this deque, or <tt>null</tt> if this deque is empty       * @return the head of this deque, or {@code null} if this deque is empty
264       */       */
265      E pollFirst();      E pollFirst();
266    
267      /**      /**
268       * Retrieves and removes the last element of this deque,       * Retrieves and removes the last element of this deque,
269       * or returns <tt>null</tt> if this deque is empty.       * or returns {@code null} if this deque is empty.
270       *       *
271       * @return the tail of this deque, or <tt>null</tt> if this deque is empty       * @return the tail of this deque, or {@code null} if this deque is empty
272       */       */
273      E pollLast();      E pollLast();
274    
# Line 295  Line 295 
295    
296      /**      /**
297       * Retrieves, but does not remove, the first element of this deque,       * Retrieves, but does not remove, the first element of this deque,
298       * or returns <tt>null</tt> if this deque is empty.       * or returns {@code null} if this deque is empty.
299       *       *
300       * @return the head of this deque, or <tt>null</tt> if this deque is empty       * @return the head of this deque, or {@code null} if this deque is empty
301       */       */
302      E peekFirst();      E peekFirst();
303    
304      /**      /**
305       * Retrieves, but does not remove, the last element of this deque,       * Retrieves, but does not remove, the last element of this deque,
306       * or returns <tt>null</tt> if this deque is empty.       * or returns {@code null} if this deque is empty.
307       *       *
308       * @return the tail of this deque, or <tt>null</tt> if this deque is empty       * @return the tail of this deque, or {@code null} if this deque is empty
309       */       */
310      E peekLast();      E peekLast();
311    
312      /**      /**
313       * Removes the first occurrence of the specified element from this deque.       * Removes the first occurrence of the specified element from this deque.
314       * If the deque does not contain the element, it is unchanged.       * If the deque does not contain the element, it is unchanged.
315       * More formally, removes the first element <tt>e</tt> such that       * More formally, removes the first element {@code e} such that
316       * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>       * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
317       * (if such an element exists).       * (if such an element exists).
318       * Returns <tt>true</tt> if this deque contained the specified element       * Returns {@code true} if this deque contained the specified element
319       * (or equivalently, if this deque changed as a result of the call).       * (or equivalently, if this deque changed as a result of the call).
320       *       *
321       * @param o element to be removed from this deque, if present       * @param o element to be removed from this deque, if present
322       * @return <tt>true</tt> if an element was removed as a result of this call       * @return {@code true} if an element was removed as a result of this call
323       * @throws ClassCastException if the class of the specified element       * @throws ClassCastException if the class of the specified element
324       *         is incompatible with this deque (optional)       *         is incompatible with this deque (optional)
325       * @throws NullPointerException if the specified element is null and this       * @throws NullPointerException if the specified element is null and this
# Line 330  Line 330 
330      /**      /**
331       * Removes the last occurrence of the specified element from this deque.       * Removes the last occurrence of the specified element from this deque.
332       * If the deque does not contain the element, it is unchanged.       * If the deque does not contain the element, it is unchanged.
333       * More formally, removes the last element <tt>e</tt> such that       * More formally, removes the last element {@code e} such that
334       * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>       * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
335       * (if such an element exists).       * (if such an element exists).
336       * Returns <tt>true</tt> if this deque contained the specified element       * Returns {@code true} if this deque contained the specified element
337       * (or equivalently, if this deque changed as a result of the call).       * (or equivalently, if this deque changed as a result of the call).
338       *       *
339       * @param o element to be removed from this deque, if present       * @param o element to be removed from this deque, if present
340       * @return <tt>true</tt> if an element was removed as a result of this call       * @return {@code true} if an element was removed as a result of this call
341       * @throws ClassCastException if the class of the specified element       * @throws ClassCastException if the class of the specified element
342       *         is incompatible with this deque (optional)       *         is incompatible with this deque (optional)
343       * @throws NullPointerException if the specified element is null and this       * @throws NullPointerException if the specified element is null and this
# Line 351  Line 351 
351       * Inserts the specified element into the queue represented by this deque       * Inserts the specified element into the queue represented by this deque
352       * (in other words, at the tail of this deque) if it is possible to do so       * (in other words, at the tail of this deque) if it is possible to do so
353       * immediately without violating capacity restrictions, returning       * immediately without violating capacity restrictions, returning
354       * <tt>true</tt> upon success and throwing an       * {@code true} upon success and throwing an
355       * <tt>IllegalStateException</tt> if no space is currently available.       * {@code IllegalStateException} if no space is currently available.
356       * When using a capacity-restricted deque, it is generally preferable to       * When using a capacity-restricted deque, it is generally preferable to
357       * use {@link #offer(Object) offer}.       * use {@link #offer(Object) offer}.
358       *       *
359       * <p>This method is equivalent to {@link #addLast}.       * <p>This method is equivalent to {@link #addLast}.
360       *       *
361       * @param e the element to add       * @param e the element to add
362       * @return <tt>true</tt> (as specified by {@link Collection#add})       * @return {@code true} (as specified by {@link Collection#add})
363       * @throws IllegalStateException if the element cannot be added at this       * @throws IllegalStateException if the element cannot be added at this
364       *         time due to capacity restrictions       *         time due to capacity restrictions
365       * @throws ClassCastException if the class of the specified element       * @throws ClassCastException if the class of the specified element
# Line 375  Line 375 
375       * Inserts the specified element into the queue represented by this deque       * Inserts the specified element into the queue represented by this deque
376       * (in other words, at the tail of this deque) if it is possible to do so       * (in other words, at the tail of this deque) if it is possible to do so
377       * immediately without violating capacity restrictions, returning       * immediately without violating capacity restrictions, returning
378       * <tt>true</tt> upon success and <tt>false</tt> if no space is currently       * {@code true} upon success and {@code false} if no space is currently
379       * available.  When using a capacity-restricted deque, this method is       * available.  When using a capacity-restricted deque, this method is
380       * generally preferable to the {@link #add} method, which can fail to       * generally preferable to the {@link #add} method, which can fail to
381       * insert an element only by throwing an exception.       * insert an element only by throwing an exception.
# Line 383  Line 383 
383       * <p>This method is equivalent to {@link #offerLast}.       * <p>This method is equivalent to {@link #offerLast}.
384       *       *
385       * @param e the element to add       * @param e the element to add
386       * @return <tt>true</tt> if the element was added to this deque, else       * @return {@code true} if the element was added to this deque, else
387       *         <tt>false</tt>       *         {@code false}
388       * @throws ClassCastException if the class of the specified element       * @throws ClassCastException if the class of the specified element
389       *         prevents it from being added to this deque       *         prevents it from being added to this deque
390       * @throws NullPointerException if the specified element is null and this       * @throws NullPointerException if the specified element is null and this
# Line 410  Line 410 
410      /**      /**
411       * Retrieves and removes the head of the queue represented by this deque       * Retrieves and removes the head of the queue represented by this deque
412       * (in other words, the first element of this deque), or returns       * (in other words, the first element of this deque), or returns
413       * <tt>null</tt> if this deque is empty.       * {@code null} if this deque is empty.
414       *       *
415       * <p>This method is equivalent to {@link #pollFirst()}.       * <p>This method is equivalent to {@link #pollFirst()}.
416       *       *
417       * @return the first element of this deque, or <tt>null</tt> if       * @return the first element of this deque, or {@code null} if
418       *         this deque is empty       *         this deque is empty
419       */       */
420      E poll();      E poll();
# Line 435  Line 435 
435      /**      /**
436       * Retrieves, but does not remove, the head of the queue represented by       * Retrieves, but does not remove, the head of the queue represented by
437       * this deque (in other words, the first element of this deque), or       * this deque (in other words, the first element of this deque), or
438       * returns <tt>null</tt> if this deque is empty.       * returns {@code null} if this deque is empty.
439       *       *
440       * <p>This method is equivalent to {@link #peekFirst()}.       * <p>This method is equivalent to {@link #peekFirst()}.
441       *       *
442       * @return the head of the queue represented by this deque, or       * @return the head of the queue represented by this deque, or
443       *         <tt>null</tt> if this deque is empty       *         {@code null} if this deque is empty
444       */       */
445      E peek();      E peek();
446    
# Line 451  Line 451 
451       * Pushes an element onto the stack represented by this deque (in other       * Pushes an element onto the stack represented by this deque (in other
452       * words, at the head of this deque) if it is possible to do so       * words, at the head of this deque) if it is possible to do so
453       * immediately without violating capacity restrictions, returning       * immediately without violating capacity restrictions, returning
454       * <tt>true</tt> upon success and throwing an       * {@code true} upon success and throwing an
455       * <tt>IllegalStateException</tt> if no space is currently available.       * {@code IllegalStateException} if no space is currently available.
456       *       *
457       * <p>This method is equivalent to {@link #addFirst}.       * <p>This method is equivalent to {@link #addFirst}.
458       *       *
# Line 486  Line 486 
486      /**      /**
487       * Removes the first occurrence of the specified element from this deque.       * Removes the first occurrence of the specified element from this deque.
488       * If the deque does not contain the element, it is unchanged.       * If the deque does not contain the element, it is unchanged.
489       * More formally, removes the first element <tt>e</tt> such that       * More formally, removes the first element {@code e} such that
490       * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>       * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>
491       * (if such an element exists).       * (if such an element exists).
492       * Returns <tt>true</tt> if this deque contained the specified element       * Returns {@code true} if this deque contained the specified element
493       * (or equivalently, if this deque changed as a result of the call).       * (or equivalently, if this deque changed as a result of the call).
494       *       *
495       * <p>This method is equivalent to {@link #removeFirstOccurrence}.       * <p>This method is equivalent to {@link #removeFirstOccurrence}.
496       *       *
497       * @param o element to be removed from this deque, if present       * @param o element to be removed from this deque, if present
498       * @return <tt>true</tt> if an element was removed as a result of this call       * @return {@code true} if an element was removed as a result of this call
499       * @throws ClassCastException if the class of the specified element       * @throws ClassCastException if the class of the specified element
500       *         is incompatible with this deque (optional)       *         is incompatible with this deque (optional)
501       * @throws NullPointerException if the specified element is null and this       * @throws NullPointerException if the specified element is null and this
# Line 504  Line 504 
504      boolean remove(Object o);      boolean remove(Object o);
505    
506      /**      /**
507       * Returns <tt>true</tt> if this deque contains the specified element.       * Returns {@code true} if this deque contains the specified element.
508       * More formally, returns <tt>true</tt> if and only if this deque contains       * More formally, returns {@code true} if and only if this deque contains
509       * at least one element <tt>e</tt> such that       * at least one element {@code e} such that
510       * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.       * <tt>(o==null&nbsp;?&nbsp;e==null&nbsp;:&nbsp;o.equals(e))</tt>.
511       *       *
512       * @param o element whose presence in this deque is to be tested       * @param o element whose presence in this deque is to be tested
513       * @return <tt>true</tt> if this deque contains the specified element       * @return {@code true} if this deque contains the specified element
514       * @throws ClassCastException if the type of the specified element       * @throws ClassCastException if the type of the specified element
515       *         is incompatible with this deque (optional)       *         is incompatible with this deque (optional)
516       * @throws NullPointerException if the specified element is null and this       * @throws NullPointerException if the specified element is null and this

Legend:
Removed from v.1.21  
changed lines
  Added in v.1.22

Doug Lea
ViewVC Help
Powered by ViewVC 1.0.8