public abstract class AbstractQueue
extends AbstractCollection<E> implements Queue<E>
| java.lang.Object | ||
| ↳ | java.util.AbstractCollection<E> | |
| ↳ | java.util.AbstractQueue<E> | |
|
ArrayBlockingQueue<E>,
ConcurrentLinkedQueue<E>,
DelayQueue<E extends
Delayed>,
LinkedBlockingDeque<E>,
LinkedBlockingQueue<E>,
LinkedTransferQueue<E>,
PriorityBlockingQueue<E>,
PriorityQueue<E>,
SynchronousQueue<E>
|
这个类提供了一些Queue操作的骨架实现。 当基实现不允许在这个类的实现方式是合适null元件。 方法add , remove ,并element基于offer , poll ,并peek ,分别,但抛出异常而不是通过指示故障false或者null回报。
甲Queue扩展此类实现必须最低限度地限定的方法offer(E)它不允许插入null元素,用方法一起peek() , poll() , size() ,和iterator() 。 通常,其他方法也将被覆盖。 如果这些要求不能满足,请考虑改为AbstractCollection 。
Protected constructors |
|
|---|---|
AbstractQueue() 构造函数由子类使用。 |
|
Public methods |
|
|---|---|
boolean |
add(E e) 将指定的元素插入此队列中,如果它是立即可行且不会违反容量限制,返回 |
boolean |
addAll(Collection<? extends E> c) 将指定集合中的所有元素添加到此队列中。 |
void |
clear() 删除此队列中的所有元素。 |
E |
element() 检索但不删除此队列的头部。 |
E |
remove() 检索并删除此队列的头部。 |
Inherited methods |
|
|---|---|
java.util.AbstractCollection
|
|
java.lang.Object
|
|
java.util.Collection
|
|
java.util.Queue
|
|
java.lang.Iterable
|
|
boolean add (E e)
将指定的元素插入此队列中,如果它是立即可行且不会违反容量限制,返回 true在成功和抛出 IllegalStateException ,如果当前没有空间可用。
如果 offer成功,则此实现返回 true ,否则返回 IllegalStateException 。
| Parameters | |
|---|---|
e |
E: the element to add |
| Returns | |
|---|---|
boolean |
true (as specified by add(E)) |
| Throws | |
|---|---|
IllegalStateException |
if the element cannot be added at this time due to capacity restrictions |
ClassCastException |
if the class of the specified element prevents it from being added to this queue |
NullPointerException |
if the specified element is null and this queue does not permit null elements |
IllegalArgumentException |
if some property of this element prevents it from being added to this queue |
boolean addAll (Collection<? extends E> c)
将指定集合中的所有元素添加到此队列中。 尝试将全部队列添加到自身导致IllegalArgumentException 。 此外,如果在操作正在进行时修改了指定的集合,则此操作的行为未定义。
该实现迭代指定的集合,并将迭代器返回的每个元素依次添加到该队列中。 尝试添加元素(特别是,包含null元素)时遇到运行时异常,可能会导致只有某些元素在引发关联异常时成功添加。
| Parameters | |
|---|---|
c |
Collection: collection containing elements to be added to this queue |
| Returns | |
|---|---|
boolean |
true if this queue changed as a result of the call |
| Throws | |
|---|---|
ClassCastException |
if the class of an element of the specified collection prevents it from being added to this queue |
NullPointerException |
if the specified collection contains a null element and this queue does not permit null elements, or if the specified collection is null |
IllegalArgumentException |
if some property of an element of the specified collection prevents it from being added to this queue, or if the specified collection is this queue |
IllegalStateException |
if not all the elements can be added at this time due to insertion restrictions |
也可以看看:
E element ()
检索但不删除此队列的头部。 此方法与peek仅在于,如果此队列为空,则会引发异常。
除非队列为空,否则此实现将返回 peek的结果。
| Returns | |
|---|---|
E |
the head of this queue |
| Throws | |
|---|---|
NoSuchElementException |
if this queue is empty |
E remove ()
检索并删除此队列的头部。 此方法与poll仅在于,如果此队列为空,则会引发异常。
除非队列为空,否则此实现返回 poll的结果。
| Returns | |
|---|---|
E |
the head of this queue |
| Throws | |
|---|---|
NoSuchElementException |
if this queue is empty |