|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
java.lang.Objectjava.util.AbstractCollection<E>
java.util.AbstractQueue<E>
java.util.concurrent.LinkedBlockingDeque<E>
E - 保存在此 collection 中的元素类型
public class LinkedBlockingDeque<E>
一个基于已链接节点的、任选范围的阻塞双端队列。
可选的容量范围构造方法参数是一种防止过度膨胀的方式。如果未指定容量,那么容量将等于 Integer.MAX_VALUE。只要插入元素不会使双端队列超出容量,每次插入后都将动态地创建链接节点。
大多数操作都以固定时间运行(不计阻塞消耗的时间)。异常包括 remove、removeFirstOccurrence、removeLastOccurrence、contains、iterator.remove() 以及批量操作,它们均以线性时间运行。
此类及其迭代器实现 Collection 和 Iterator 接口的所有可选 方法。
此类是 Java Collections Framework 的成员。
| 构造方法摘要 | |
|---|---|
LinkedBlockingDeque() 创建一个容量为 Integer.MAX_VALUE 的 LinkedBlockingDeque。 |
|
LinkedBlockingDeque(Collection<? extends E> c) 创建一个容量为 Integer.MAX_VALUE 的 LinkedBlockingDeque,最初包含给定 collection 的元素,以该 collection 迭代器的遍历顺序添加。 |
|
LinkedBlockingDeque(int capacity) 创建一个具有给定(固定)容量的 LinkedBlockingDeque。 |
|
| 方法摘要 | ||
|---|---|---|
boolean |
add(E e) 在不违反容量限制的情况下,将指定的元素插入此双端队列的末尾。 |
|
void |
addFirst(E e) 如果立即可行且不违反容量限制,则将指定的元素插入此双端队列的开头;如果当前没有空间可用,则抛出 IllegalStateException。 |
|
void |
addLast(E e) 如果立即可行且不违反容量限制,则将指定的元素插入此双端队列的末尾;如果当前没有空间可用,则抛出 IllegalStateException。 |
|
void |
clear() 以原子方式 (atomically) 从此双端队列移除所有元素。 |
|
boolean |
contains(Object o) 如果此双端队列包含指定的元素,则返回 true。 |
|
Iterator<E> |
descendingIterator() 返回在此双端队列的元素上以逆向连续顺序进行迭代的迭代器。 |
|
int |
drainTo(Collection<? super E> c) 移除此队列中所有可用的元素,并将它们添加到给定 collection 中。 |
|
int |
drainTo(Collection<? super E> c, int maxElements) 最多从此队列中移除给定数量的可用元素,并将这些元素添加到给定 collection 中。 |
|
E |
element() 获取但不移除此双端队列表示的队列的头部。 |
|
E |
getFirst() 获取,但不移除此双端队列的第一个元素。 |
|
E |
getLast() 获取,但不移除此双端队列的最后一个元素。 |
|
Iterator<E> |
iterator() 返回在此双端队列元素上以恰当顺序进行迭代的迭代器。 |
|
boolean |
offer(E e) 如果立即可行且不违反容量限制,则将指定的元素插入此双端队列表示的队列中(即此双端队列的尾部),并在成功时返回 true;如果当前没有空间可用,则返回 false。 |
|
boolean |
offer(E e, long timeout, TimeUnit unit) 将指定的元素插入此双端队列表示的队列中(即此双端队列的尾部),必要时将在指定的等待时间内一直等待可用空间。 |
|
boolean |
offerFirst(E e) 如果立即可行且不违反容量限制,则将指定的元素插入此双端队列的开头,并在成功时返回 true;如果当前没有空间可用,则返回 false。 |
|
boolean |
offerFirst(E e, long timeout, TimeUnit unit) 将指定的元素插入此双端队列的开头,必要时将在指定的等待时间内等待可用空间。 |
|
boolean |
offerLast(E e) 如果立即可行且不违反容量限制,则将指定的元素插入此双端队列的末尾,并在成功时返回 true;如果当前没有空间可用,则返回 false。 |
|
boolean |
offerLast(E e, long timeout, TimeUnit unit) 将指定的元素插入此双端队列的末尾,必要时将在指定的等待时间内等待可用空间。 |
|
E |
peek() 获取但不移除此双端队列表示的队列的头部(即此双端队列的第一个元素);如果此双端队列为空,则返回 null。 |
|
E |
peekFirst() 获取,但不移除此双端队列的第一个元素;如果此双端队列为空,则返回 null。 |
|
E |
peekLast() 获取,但不移除此双端队列的最后一个元素;如果此双端队列为空,则返回 null。 |
|
E |
poll() 获取并移除此双端队列表示的队列的头部(即此双端队列的第一个元素);如果此双端队列为空,则返回 null。 |
|
E |
poll(long timeout, TimeUnit unit) 获取并移除此双端队列表示的队列的头部(即此双端队列的第一个元素),如有必要将在指定的等待时间内等待可用元素。 |
|
E |
pollFirst() 获取并移除此双端队列的第一个元素;如果此双端队列为空,则返回 null。 |
|
E |
pollFirst(long timeout, TimeUnit unit) 获取并移除此双端队列的第一个元素,必要时将在指定的等待时间等待可用元素。 |
|
E |
pollLast() 获取并移除此双端队列的最后一个元素;如果此双端队列为空,则返回 null。 |
|
E |
pollLast(long timeout, TimeUnit unit) 获取并移除此双端队列的最后一个元素,必要时将在指定的等待时间内等待可用元素。 |
|
E |
pop() 从此双端队列所表示的堆栈中弹出一个元素。 |
|
void |
push(E e) 将元素推入此双端队列表示的栈。 |
|
void |
put(E e) 将指定的元素插入此双端队列表示的队列中(即此双端队列的尾部),必要时将一直等待可用空间。 |
|
void |
putFirst(E e) 将指定的元素插入此双端队列的开头,必要时将一直等待可用空间。 |
|
void |
putLast(E e) 将指定的元素插入此双端队列的末尾,必要时将一直等待可用空间。 |
|
int |
remainingCapacity() 返回理想情况下(没有内存和资源约束)此双端队列可不受阻塞地接受的额外元素数。 |
|
E |
remove() 获取并移除此双端队列表示的队列的头部。 |
|
boolean |
remove(Object o) 从此双端队列移除第一次出现的指定元素。 |
|
E |
removeFirst() 获取并移除此双端队列第一个元素。 |
|
boolean |
removeFirstOccurrence(Object o) 从此双端队列移除第一次出现的指定元素。 |
|
E |
removeLast() 获取并移除此双端队列的最后一个元素。 |
|
boolean |
removeLastOccurrence(Object o) 从此双端队列移除最后一次出现的指定元素。 |
|
int |
size() 返回此双端队列中的元素数。 |
|
E |
take() 获取并移除此双端队列表示的队列的头部(即此双端队列的第一个元素),必要时将一直等待可用元素。 |
|
E |
takeFirst() 获取并移除此双端队列的第一个元素,必要时将一直等待可用元素。 |
|
E |
takeLast() 获取并移除此双端队列的最后一个元素,必要时将一直等待可用元素。 |
|
Object[] |
toArray() 返回以恰当顺序(从第一个元素到最后一个元素)包含此双端队列所有元素的数组。 |
|
|
toArray(T[] a) 返回以恰当顺序包含此双端队列所有元素的数组;返回数组的运行时类型是指定数组的运行时类型。 |
|
String |
toString() 返回此 collection 的字符串表示形式。 |
|
| 从类 java.util.AbstractQueue 继承的方法 |
|---|
addAll |
| 从类 java.util.AbstractCollection 继承的方法 |
|---|
containsAll, isEmpty, removeAll, retainAll |
| 从类 java.lang.Object 继承的方法 |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| 从接口 java.util.Collection 继承的方法 |
|---|
addAll, containsAll, equals, hashCode, isEmpty, removeAll, retainAll |
| 构造方法详细信息 |
|---|
public LinkedBlockingDeque()
Integer.MAX_VALUE 的
LinkedBlockingDeque。
public LinkedBlockingDeque(int capacity)
capacity - 此双端队列的容量
IllegalArgumentException - 如果
capacity 小于 1
public LinkedBlockingDeque(Collection<? extends E> c)
Integer.MAX_VALUE 的
LinkedBlockingDeque,最初包含给定 collection 的元素,以该 collection 迭代器的遍历顺序添加。
c - 最初所包含元素所属的 collection
NullPointerException - 如果指定 collection 或其任意元素为 null
| 方法详细信息 |
|---|
public void addFirst(E e)
BlockingDeque 复制的描述
offerFirst。
BlockingDeque<E> 中的
addFirst
Deque<E> 中的
addFirst
e - 要添加的元素
IllegalStateException - 如果此时由于容量限制而无法添加元素
NullPointerException - 如果指定的元素为 null
public void addLast(E e)
BlockingDeque 复制的描述
offerLast。
BlockingDeque<E> 中的
addLast
Deque<E> 中的
addLast
e - 要添加的元素
IllegalStateException - 如果此时由于容量限制而无法添加元素
NullPointerException - 如果指定的元素为 null
public boolean offerFirst(E e)
BlockingDeque 复制的描述
addFirst 方法,后者可能无法插入元素,而只是抛出一个异常。
BlockingDeque<E> 中的
offerFirst
Deque<E> 中的
offerFirst
e - 要添加的元素
NullPointerException - 如果指定的元素为 null
public boolean offerLast(E e)
BlockingDeque 复制的描述
addLast 方法,后者可能无法插入元素,而只是抛出一个异常。
BlockingDeque<E> 中的
offerLast
Deque<E> 中的
offerLast
e - 要添加的元素
NullPointerException - 如果指定的元素为 null
public void putFirst(E e)
throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的
putFirst
e - 要添加的元素
NullPointerException - 如果指定的元素为 null
InterruptedException - 如果在等待时被中断
public void putLast(E e)
throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的
putLast
e - 要添加的元素
NullPointerException - 如果指定的元素为 null
InterruptedException - 如果在等待时被中断
public boolean offerFirst(E e,
long timeout,
TimeUnit unit)
throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的
offerFirst
e - 要添加的元素
timeout - 放弃之前等待的时间长度,以
unit 为时间单位
unit - 确定如何解释
timeout 参数的
TimeUnit
NullPointerException - 如果指定的元素为 null
InterruptedException - 如果在等待时被中断
public boolean offerLast(E e,
long timeout,
TimeUnit unit)
throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的
offerLast
e - 要添加的元素
timeout - 放弃之前等待的时间长度,以
unit 为时间单位
unit - 确定如何解释
timeout 参数的
TimeUnit
NullPointerException - 如果指定的元素为 null
InterruptedException - 如果在等待时被中断
public E removeFirst()
Deque 复制的描述
pollFirst 唯一的不同在于:如果此双端队列为空,它将抛出一个异常。
Deque<E> 中的
removeFirst
NoSuchElementException - 如果此双端队列为空
public E removeLast()
Deque 复制的描述
pollLast 唯一的不同在于:如果此双端队列为空,它将抛出一个异常。
Deque<E> 中的
removeLast
NoSuchElementException - 如果此双端队列为空
public E pollFirst()
Deque 复制的描述
Deque<E> 中的
pollFirst
public E pollLast()
Deque 复制的描述
Deque<E> 中的
pollLast
public E takeFirst()
throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的
takeFirst
InterruptedException - 如果在等待时被中断
public E takeLast()
throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的
takeLast
InterruptedException - 如果在等待时被中断
public E pollFirst(long timeout,
TimeUnit unit)
throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的
pollFirst
timeout - 放弃之前等待的时间长度,以
unit 为时间单位
unit - 确定如何解释
timeout 参数的
TimeUnit
InterruptedException - 如果在等待时被中断
public E pollLast(long timeout,
TimeUnit unit)
throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的
pollLast
timeout - 放弃之前等待的时间长度,以
unit 为时间单位
unit - 确定如何解释
timeout 参数的
TimeUnit
InterruptedException - 如果在等待时被中断
public E getFirst()
Deque 复制的描述
peekFirst 唯一的不同在于:如果此双端队列为空,它将抛出一个异常。
Deque<E> 中的
getFirst
NoSuchElementException - 如果此双端队列为空
public E getLast()
Deque 复制的描述
peekLast 唯一的不同在于:如果此双端队列为空,它将抛出一个异常。
Deque<E> 中的
getLast
NoSuchElementException - 如果此双端队列为空
public E peekFirst()
Deque 复制的描述
Deque<E> 中的
peekFirst
public E peekLast()
Deque 复制的描述
Deque<E> 中的
peekLast
public boolean removeFirstOccurrence(Object o)
BlockingDeque 复制的描述
BlockingDeque<E> 中的
removeFirstOccurrence
Deque<E> 中的
removeFirstOccurrence
o - 要从此双端队列移除的元素(如果存在)
public boolean removeLastOccurrence(Object o)
BlockingDeque 复制的描述
BlockingDeque<E> 中的
removeLastOccurrence
Deque<E> 中的
removeLastOccurrence
o - 要从此双端队列移除的元素(如果存在)
public boolean add(E e)
offer 方法。
此方法等效于 addLast(E)。
Collection<E> 中的
add
BlockingDeque<E> 中的
add
BlockingQueue<E> 中的
add
Deque<E> 中的
add
Queue<E> 中的
add
AbstractQueue<E> 中的
add
e - 要添加的元素
Collection.add(E) 的规定)
IllegalStateException - 如果此刻由于容量限制而无法添加元素
NullPointerException - 如果指定的元素为 null
public boolean offer(E e)
BlockingDeque 复制的描述
BlockingDeque.add(E) 方法,后者可能无法插入元素,而只是抛出一个异常。
此方法等效于 offerLast。
BlockingDeque<E> 中的
offer
BlockingQueue<E> 中的
offer
Deque<E> 中的
offer
Queue<E> 中的
offer
e - 要添加的元素
NullPointerException - 如果指定的元素为 null
public void put(E e)
throws InterruptedException
BlockingDeque 复制的描述
此方法等效于 putLast。
BlockingDeque<E> 中的
put
BlockingQueue<E> 中的
put
e - 要添加的元素
NullPointerException - 如果指定的元素为 null
InterruptedException - 如果在等待时被中断
public boolean offer(E e,
long timeout,
TimeUnit unit)
throws InterruptedException
BlockingDeque 复制的描述
此方法等效于 offerLast。
BlockingDeque<E> 中的
offer
BlockingQueue<E> 中的
offer
e - 要添加的元素
timeout - 放弃之前等待的时间长度,以
unit 为时间单位
unit - 确定如何解释
timeout 参数的
TimeUnit
NullPointerException - 如果指定的元素为 null
InterruptedException - 如果在等待时被中断
public E remove()
poll 的不同之处在于:如果此双端队列为空,它将抛出一个异常。
此方法等效于 removeFirst。
BlockingDeque<E> 中的
remove
Deque<E> 中的
remove
Queue<E> 中的
remove
AbstractQueue<E> 中的
remove
NoSuchElementException - 如果此双端队列为空
public E poll()
BlockingDeque 复制的描述
此方法等效于 Deque.pollFirst()。
BlockingDeque<E> 中的
poll
Deque<E> 中的
poll
Queue<E> 中的
poll
public E take()
throws InterruptedException
BlockingDeque 复制的描述
此方法等效于 takeFirst。
BlockingDeque<E> 中的
take
BlockingQueue<E> 中的
take
InterruptedException - 如果在等待时被中断
public E poll(long timeout,
TimeUnit unit)
throws InterruptedException
BlockingDeque 复制的描述
此方法等效于 pollFirst。
BlockingDeque<E> 中的
poll
BlockingQueue<E> 中的
poll
timeout - 放弃之前要等待的时间长度,用
unit 的时间单位表示
unit - 确定如何解释
timeout 参数的
TimeUnit
InterruptedException - 如果在等待时被中断
public E element()
peek 的不同之处在于:如果此双端队列为空,它将抛出一个异常。
此方法等效于 getFirst。
BlockingDeque<E> 中的
element
Deque<E> 中的
element
Queue<E> 中的
element
AbstractQueue<E> 中的
element
NoSuchElementException - 如果此双端队列为空
public E peek()
BlockingDeque 复制的描述
此方法等效于 peekFirst。
BlockingDeque<E> 中的
peek
Deque<E> 中的
peek
Queue<E> 中的
peek
public int remainingCapacity()
注意,不能 总是通过检查 remainingCapacity 断定试图插入元素能否成功,因为可能出现另一个线程即将插入或移除一个元素的情况。
BlockingQueue<E> 中的
remainingCapacity
public int drainTo(Collection<? super E> c)
BlockingQueue 复制的描述
BlockingQueue<E> 中的
drainTo
c - 接收传输元素的 collection
UnsupportedOperationException - 如果指定 collection 不支持添加元素
ClassCastException - 如果此队列元素的类不允许将其添加到指定 collection
NullPointerException - 如果指定 collection 为 null
IllegalArgumentException - 如果指定 collection 是此队列,或者此队列元素的某些属性不允许将其添加到指定 collection
public int drainTo(Collection<? super E> c,
int maxElements)
BlockingQueue 复制的描述
BlockingQueue<E> 中的
drainTo
c - 接收传输元素的 collection
maxElements - 传输元素的最大数量
UnsupportedOperationException - 如果指定 collection 不支持添加元素
ClassCastException - 如果此队列元素的类不允许将其添加到指定 collection
NullPointerException - 如果指定 collection 为 null
IllegalArgumentException - 如果指定 collection 是此队列,或者此队列元素的某些属性不允许将其添加到指定 collection
public void push(E e)
BlockingDeque 复制的描述
此方法等效于 addFirst。
BlockingDeque<E> 中的
push
Deque<E> 中的
push
e - 要推入的元素
IllegalStateException - 如果此时由于容量限制而无法添加元素
NullPointerException - 如果指定的元素为 null
public E pop()
Deque 复制的描述
此方法等效于 Deque.removeFirst()。
Deque<E> 中的
pop
NoSuchElementException - 如果此双端队列为空
public boolean remove(Object o)
此方法等效于 removeFirstOccurrence。
Collection<E> 中的
remove
BlockingDeque<E> 中的
remove
BlockingQueue<E> 中的
remove
Deque<E> 中的
remove
AbstractCollection<E> 中的
remove
o - 要从此双端队列移除的元素(如果存在)
public int size()
Collection<E> 中的
size
BlockingDeque<E> 中的
size
Deque<E> 中的
size
AbstractCollection<E> 中的
size
public boolean contains(Object o)
Collection<E> 中的
contains
BlockingDeque<E> 中的
contains
BlockingQueue<E> 中的
contains
Deque<E> 中的
contains
AbstractCollection<E> 中的
contains
o - 检查是否包含于此双端队列的对象
public Object[] toArray()
由于此双端队列不维护对返回数组的任何引用,因而它将是“安全的”。(换句话说,此方法必须分配一个新的数组)。因此,调用者可以自由地修改返回的数组。
此方法充当了基于数组的 API 与基于 collection 的 API 之间的桥梁。
Collection<E> 中的
toArray
AbstractCollection<E> 中的
toArray
public <T> T[] toArray(T[] a)
如果指定的数组能容纳此双端队列,并且有剩余的空间(即数组的元素比双端队列多),那么将数组中紧接双端队列尾部的元素设置为 null。
像 toArray() 方法一样,此方法充当基于数组 的 API 与基于 collection 的 API 之间的桥梁。更进一步说,此方法允许对输出数组的运行时类型进行精确控制,在某些情况下,还可以用来节省分配开销。
假定 x 是只包含字符串的一个已知双端队列。以下代码用来将该双端队列转储到一个新分配的 String 数组:
String[] y = x.toArray(new String[0]);注意, toArray(new Object[0]) 和 toArray() 在功能上是相同的。
Collection<E> 中的
toArray
AbstractCollection<E> 中的
toArray
a - 要用来存储双端队列元素的数组(如果该数组足够大);否则,将为此分配一个具有相同运行时类型的新数组
ArrayStoreException - 如果指定数组的运行时类型不是此双端队列每个元素的运行时类型的超类型
NullPointerException - 如果指定的数组为 null
public String toString()
AbstractCollection 复制的描述
String.valueOf(Object) 可以将元素转换成字符串。
AbstractCollection<E> 中的
toString
public void clear()
Collection<E> 中的
clear
AbstractQueue<E> 中的
clear
public Iterator<E> iterator()
ConcurrentModificationException 的“弱一致”迭代器,能确保遍历迭代器构造后存在的所有元素,并可以(但并不保证)反映构造后的任何修改。
Iterable<E> 中的
iterator
Collection<E> 中的
iterator
BlockingDeque<E> 中的
iterator
Deque<E> 中的
iterator
AbstractCollection<E> 中的
iterator
public Iterator<E> descendingIterator()
ConcurrentModificationException 的“弱一致”迭代器,能确保遍历迭代器构造后存在的所有元素,并可以(但并不保证)反映构造后的任何修改。
Deque<E> 中的
descendingIterator
|
JavaTM Platform Standard Ed. 6 |
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。