AbstractQueue

王朝百科·作者佚名  2010-01-10
窄屏简体版  字體: |||超大  

java.util

类 AbstractQueue<E>

java.lang.Object

java.util.AbstractCollection<E>

java.util.AbstractQueue<E>

类型参数:

E - 此 collection 中所保存元素的类型

所有已实现的接口:

Iterable<E>, Collection<E>, Queue<E>

直接已知子类:

ArrayBlockingQueue, ConcurrentLinkedQueue, DelayQueue, LinkedBlockingQueue, PriorityBlockingQueue, PriorityQueue, SynchronousQueue

--------------------------------------------------------------------------------

public abstract class AbstractQueue<E>extends AbstractCollection<E>implements Queue<E>此类提供某些 Queue 操作的骨干实现。此类中的实现适用于基本实现不 允许包含 null 元素时。add、remove 和 element 方法分别基于 offer、poll 和 peek 方法,但是它们通过抛出异常而不是返回 false 或 null 来指示失败。

扩展此类的 Queue 实现至少必须定义一个不允许插入 null 元素的 Queue.offer(E) 方法,该方法以及 Queue.peek()、Queue.poll()、Collection.size() 和 Collection.iterator() 都支持 Iterator.remove() 方法。通常还要重写其他方法。如果无法满足这些要求,那么可以转而考虑为 AbstractCollection 创建子类。

此类是 Java Collections Framework 的成员。

从以下版本开始:

1.5

--------------------------------------------------------------------------------

构造方法摘要

protected AbstractQueue()

子类使用的构造方法。

方法摘要

boolean add(E o)

将指定的元素添加到此队列中。

boolean addAll(Collection<? extends E> c)

将指定 collection 中的所有元素都添加到此队列中。

void clear()

移除此 collection 中的所有元素。

E element()

检索但不移除此队列的头。

E remove()

检索并移除此队列的头。

从类 java.util.AbstractCollection 继承的方法

contains, containsAll, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray, toString

从类 java.lang.Object 继承的方法

clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

从接口 java.util.Queue 继承的方法

offer, peek, poll

从接口 java.util.Collection 继承的方法

contains, containsAll, equals, hashCode, isEmpty, iterator, remove, removeAll, retainAll, size, toArray, toArray

构造方法详细信息

AbstractQueue

protected AbstractQueue()子类使用的构造方法。

方法详细信息

add

public boolean add(E o)将指定的元素添加到此队列中。如果 offer 成功,则此实现返回 true,其他情况则抛出 IllegalStateException。

指定者:

接口 Collection<E> 中的 add

覆盖:

类 AbstractCollection<E> 中的 add

参数:

o - 元素

返回:

true(按照 Collection.add 的常规协定)。

抛出:

NullPointerException - 如果指定的元素为 null

IllegalStateException - 如果无法添加元素

--------------------------------------------------------------------------------

remove

public E remove()检索并移除此队列的头。除非队列为空,否则此实现返回 poll 的结果。

指定者:

接口 Queue<E> 中的 remove

返回:

此队列的头。

抛出:

NoSuchElementException - 如果此队列为空。

--------------------------------------------------------------------------------

element

public E element()检索但不移除此队列的头。除非队列为空,否则此实现返回 peek 的结果。

指定者:

接口 Queue<E> 中的 element

返回:

此队列的头。

抛出:

NoSuchElementException - 如果此队列为空。

--------------------------------------------------------------------------------

clear

public void clear()移除此 collection 中的所有元素。此调用返回后,collection 将为空。

此实现重复调用 poll,直到它返回 null 为止。

指定者:

接口 Collection<E> 中的 clear

覆盖:

类 AbstractCollection<E> 中的 clear

--------------------------------------------------------------------------------

addAll

public boolean addAll(Collection<? extends E> c)将指定 collection 中的所有元素都添加到此队列中。如果试图将某一队列 addAll 到该队列本身中,则会导致 IllegalArgumentException。此外,如果正在进行此操作时修改指定的 collection,则此操作的行为是不明确的。

此实现在指定的 collection 上进行迭代,并依次将迭代器返回的每一个元素添加到此 collection 中。在试图添加某一元素(尤其是 null 元素)时如果遇到了运行时异常,则可能导致在抛出相关异常时只成功地添加了某些元素。

指定者:

接口 Collection<E> 中的 addAll

覆盖:

类 AbstractCollection<E> 中的 addAll

参数:

c - 其元素将被添加到此 collection 中的 collection。

返回:

如果此 collection 由于此方法的调用而发生改变,则返回 true。

抛出:

NullPointerException - 如果指定的 collection 或其所有元素均为 null。

IllegalArgumentException - 如果 c 是此队列。

另请参见:

add(Object)

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航