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
。
这个班的一员 Java Collections Framework。
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, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
contains, containsAll, equals, hashCode, isEmpty, iterator, parallelStream, remove, removeAll, removeIf, retainAll, size, spliterator, stream, toArray, toArray
public boolean add(E e)
如果offer成功实现返回true,别人抛出一个IllegalStateException。
add
接口
Collection<E>
add
接口
Queue<E>
add
方法重写,继承类
AbstractCollection<E>
e
-元素添加
Collection.add(E)
指定)
IllegalStateException
-如果元素不能被添加在这个时候由于产能限制
ClassCastException
-如果指定元素类型阻止其加入队列
NullPointerException
-如果指定元素为null,这队列不允许null元素
IllegalArgumentException
-如果该元素的一些特性阻止其加入队列
public E remove()
poll
仅在于它抛出一个异常,如果队列为空。
此实现返回的结果poll除非队列是空的。
remove
接口
Queue<E>
NoSuchElementException
如果队列为空
public E element()
peek
仅在于它抛出一个异常,如果队列为空。
此实现返回的结果peek除非队列是空的。
element
接口
Queue<E>
NoSuchElementException
如果队列为空
public void clear()
这poll
实施多次调用返回之前null。
clear
接口
Collection<E>
clear
方法重写,继承类
AbstractCollection<E>
public boolean addAll(Collection<? extends E> c)
对指定集合进行遍历,并添加每个元素由迭代器返回到这个队列,依次。当试图添加一个元素时遇到一个运行时异常(包括,特别是,一个null元)可能只有一些元素已经成功添加相关的异常被抛出时。
addAll
接口
Collection<E>
addAll
方法重写,继承类
AbstractCollection<E>
c
收集含有的元素被添加到该队列
ClassCastException
-如果指定集合的一个元素类阻止其加入队列
NullPointerException
-如果指定集合包含一个null元素,这个队列不允许null元素,或者指定集合为空
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.