|
| 1 | +/* Copyright 1998, 2006 The Apache Software Foundation or its licensors, as applicable |
| 2 | + * |
| 3 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. |
| 5 | + * You may obtain a copy of the License at |
| 6 | + * |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * |
| 9 | + * Unless required by applicable law or agreed to in writing, software |
| 10 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + * See the License for the specific language governing permissions and |
| 13 | + * limitations under the License. |
| 14 | + */ |
| 15 | +package java.util; |
| 16 | + |
| 17 | +/** |
| 18 | + * A kind of collection provides advanced operations than other basic |
| 19 | + * collections, such as insertion, extraction, and inspection. |
| 20 | + * |
| 21 | + * Generally, a queue orders its elements by means of first-in-first-out. While |
| 22 | + * priority queue orders its elements according to a comparator specified or the |
| 23 | + * elements' natural order. Furthermore, a stack orders its elements |
| 24 | + * last-in-first out. |
| 25 | + * |
| 26 | + * A typical queue does not allow null to be inserted as its element, while some |
| 27 | + * implementations such as LinkedList allow it. But null should not be inserted |
| 28 | + * even in these implementations, since method poll return null to indicate that |
| 29 | + * there is no element left in the queue. |
| 30 | + * |
| 31 | + * Queue does not provide blocking queue methods, which will block until the |
| 32 | + * operation of the method is allowed. BlockingQueue interface defines such |
| 33 | + * methods. |
| 34 | + */ |
| 35 | +public interface Queue<E> extends Collection<E> { |
| 36 | + |
| 37 | + /** |
| 38 | + * Inserts the specified element into the queue provided that the condition |
| 39 | + * allows such an operation. The method is generally preferable to the |
| 40 | + * collection.add(E), since the latter might throw an exception if the |
| 41 | + * operation fails. |
| 42 | + * |
| 43 | + * @param o |
| 44 | + * the specified element to insert into the queue. |
| 45 | + * @return true if the operation succeeds and false if it fails. |
| 46 | + */ |
| 47 | + public boolean offer(E o); |
| 48 | + |
| 49 | + /** |
| 50 | + * Gets and removes the element in the head of the queue, or returns null if |
| 51 | + * there is no element in the queue. |
| 52 | + * |
| 53 | + * @return the element in the head of the queue or null if there is no |
| 54 | + * element in the queue. |
| 55 | + */ |
| 56 | + public E poll(); |
| 57 | + |
| 58 | + /** |
| 59 | + * Gets and removes the element in the head of the queue. Throws a |
| 60 | + * NoSuchElementException if there is no element in the queue. |
| 61 | + * |
| 62 | + * @return the element in the head of the queue. |
| 63 | + * @throws NoSuchElementException |
| 64 | + * if there is no element in the queue. |
| 65 | + */ |
| 66 | + public E remove(); |
| 67 | + |
| 68 | + /** |
| 69 | + * Gets but not removes the element in the head of the queue, or throws |
| 70 | + * exception if there is no element in the queue. |
| 71 | + * |
| 72 | + * @return the element in the head of the queue or null if there is no |
| 73 | + * element in the queue. |
| 74 | + */ |
| 75 | + public E peek(); |
| 76 | + |
| 77 | + /** |
| 78 | + * Gets but not removes the element in the head of the queue. Throws a |
| 79 | + * NoSuchElementException if there is no element in the queue. |
| 80 | + * |
| 81 | + * @return the element in the head of the queue. |
| 82 | + * @throws NoSuchElementException |
| 83 | + * if there is no element in the queue. |
| 84 | + */ |
| 85 | + public E element(); |
| 86 | + |
| 87 | +} |
0 commit comments