E - 在此集合中保存的元素的类型
public abstract class AbstractQueue<E> extends AbstractCollection<E> implements Queue<E>
Queue操作的骨架实现。
当基实现不允许 null个元件在这个类的实现是合适的。
方法add , remove和element基于offer , poll和peek ,分别,但抛出异常,而不是通过false个或null返回表示失败。
扩展此类甲Queue实现必须最低限度地限定的方法Queue.offer(E)它不允许null个元件的插入,与方法一起Queue.peek() , Queue.poll() , Collection.size()和Collection.iterator() 。 通常,其他方法也将被覆盖。 如果无法满足这些要求,请考虑将其分类为AbstractCollection 。
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractQueue()
子类使用的构造方法。
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(E e)
将指定的元素插入到此队列中,如果可以立即执行此操作而不违反容量限制,
则在成功后返回
true,如果当前没有可用空间,则抛出IllegalStateException。
|
boolean |
addAll(Collection<? extends E> c)
将指定集合中的所有元素添加到此队列中。
|
void |
clear()
从此队列中删除所有元素。
|
E |
element()
检索,但不删除,这个队列的头。
|
E |
remove()
检索并删除此队列的头。
|
contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcontains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArraypublic boolean add(E e)
如果offer成功,此实现返回true ,否则抛出一个IllegalStateException 。
add在接口
Collection<E>
add在接口
Queue<E>
add在类别
AbstractCollection<E>
e - 要添加的元素
Collection.add(E)指定 )
IllegalStateException - 如果由于容量限制,此时无法添加该元素
ClassCastException - 如果指定元素的类阻止将其添加到此队列中
NullPointerException - 如果指定的元素为空,并且该队列不允许空元素
IllegalArgumentException - 如果此元素的某些属性阻止将其添加到此队列
public E remove()
remove在界面
Queue<E>
NoSuchElementException - 如果此队列为空
public E element()
element在界面
Queue<E>
NoSuchElementException - 如果这个队列是空的
public void clear()
clear在界面
Collection<E>
clear在类别
AbstractCollection<E>
public boolean addAll(Collection<? extends E> c)
这个实现遍历指定的集合,并依次将迭代器返回的每个元素添加到此队列中。 在尝试添加元素(包括特别是null元素)时遇到的运行时异常可能会导致在抛出关联异常时只有部分元素已成功添加。
addAll在界面
Collection<E>
addAll在类别
AbstractCollection<E>
c - 包含要添加到此队列的元素的集合
ClassCastException - 如果指定集合的元素的类阻止将其添加到此队列中
NullPointerException - 如果指定的集合包含空元素,并且此队列不允许空元素,或者如果指定的集合为空
IllegalArgumentException - 如果指定集合的元素的某些属性阻止其添加到此队列中,或者如果指定的集合是此队列
IllegalStateException - 如果不是,由于插入限制,此时可以添加所有元素
add(Object)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.