AbstractQueue

来源:互联网 发布:ftp控制端口 编辑:程序博客网 时间:2024/05/15 05:13
本词条缺少名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧!
AbstractQueue是 Java Collections Framework 的成员,是一个基于优先级堆的极大优先级队列。此队列按照在构造时所指定的顺序对元素排序,既可以根据元素的自然顺序来指定排序,也可以根据 Comparator 来指定,这取决于使用哪种构造方法。优先级队列不允许 null 元素。依靠自然排序的优先级队列还不允许插入不可比较的对象。
外文名
AbstractQueue
从    属
Java Collections Framework
类    别
优先级队列
限    制
不允许 null 元素

目录

1简介

2构造方法摘要

3构造方法详细信息

4迭代

1简介编辑

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
--------------------------------------------------------------------------------

2构造方法摘要编辑

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

3构造方法详细信息编辑

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,则此操作的行为是不明确的。
PriorityQueue()
使用默认的初始容量(11)创建一个 PriorityQueue,并根据其自然顺序来排序其元素(使用 Comparable)。
PriorityQueue(Collection<? extends E> c)
创建包含指定集合中元素的 PriorityQueue。
PriorityQueue(int initialCapacity)
使用指定的初始容量创建一个 PriorityQueue,并根据其自然顺序来排序其元素(使用 Comparable)。
PriorityQueue(int initialCapacity, Comparator<? super E> comparator)
使用指定的初始容量创建一个 PriorityQueue,并根据指定的比较器来排序其元素。
PriorityQueue(PriorityQueue<? extends E> c)
创建包含指定集合中元素的 PriorityQueue。
PriorityQueue(SortedSet<? extends E> c)
创建包含指定集合中元素的 PriorityQueue。

4迭代编辑

此实现在指定的 collection 上进行迭代,并依次将迭代器返回的每一个元素添加到此 collection 中。在试图添加某一元素(尤其是 null 元素)时如果遇到了运行时异常,则可能导致在抛出相关异常时只成功地添加了某些元素。
指定者:
接口 Collection<E> 中的 addAll
覆盖:
类 AbstractCollection<E> 中的 addAll
参数:
c - 其元素将被添加到此 collection 中的 collection。
返回:
如果此 collection 由于此方法的调用而发生改变,则返回 true。
抛出:
NullPointerException - 如果指定的 collection 或其所有元素均为 null。
IllegalArgumentException - 如果 c 是此队列。
另请参见:
add(Object)
0 0
原创粉丝点击