| 
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 小于 1public LinkedBlockingDeque(Collection<? extends E> c)
Integer.MAX_VALUE 的 LinkedBlockingDeque,最初包含给定 collection 的元素,以该 collection 迭代器的遍历顺序添加。
c - 最初所包含元素所属的 collection
NullPointerException - 如果指定 collection 或其任意元素为 null| 方法详细信息 | 
|---|
public void addFirst(E e)
BlockingDeque 复制的描述offerFirst。
e - 要添加的元素
IllegalStateException - 如果此时由于容量限制而无法添加元素
NullPointerException - 如果指定的元素为 nullpublic void addLast(E e)
BlockingDeque 复制的描述offerLast。
e - 要添加的元素
IllegalStateException - 如果此时由于容量限制而无法添加元素
NullPointerException - 如果指定的元素为 nullpublic boolean offerFirst(E e)
BlockingDeque 复制的描述addFirst 方法,后者可能无法插入元素,而只是抛出一个异常。
BlockingDeque<E> 中的 offerFirstDeque<E> 中的 offerFirste - 要添加的元素
NullPointerException - 如果指定的元素为 nullpublic boolean offerLast(E e)
BlockingDeque 复制的描述addLast 方法,后者可能无法插入元素,而只是抛出一个异常。
e - 要添加的元素
NullPointerException - 如果指定的元素为 nullpublic void putFirst(E e) throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的 putFirste - 要添加的元素
NullPointerException - 如果指定的元素为 null
InterruptedException - 如果在等待时被中断public void putLast(E e) throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的 putLaste - 要添加的元素
NullPointerException - 如果指定的元素为 null
InterruptedException - 如果在等待时被中断public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的 offerFirste - 要添加的元素timeout - 放弃之前等待的时间长度,以 unit 为时间单位unit - 确定如何解释 timeout 参数的 TimeUnit
NullPointerException - 如果指定的元素为 null
InterruptedException - 如果在等待时被中断public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的 offerLaste - 要添加的元素timeout - 放弃之前等待的时间长度,以 unit 为时间单位unit - 确定如何解释 timeout 参数的 TimeUnit
NullPointerException - 如果指定的元素为 null
InterruptedException - 如果在等待时被中断public E removeFirst()
Deque 复制的描述pollFirst 唯一的不同在于:如果此双端队列为空,它将抛出一个异常。
Deque<E> 中的 removeFirstNoSuchElementException - 如果此双端队列为空public E removeLast()
Deque 复制的描述pollLast 唯一的不同在于:如果此双端队列为空,它将抛出一个异常。
Deque<E> 中的 removeLastNoSuchElementException - 如果此双端队列为空public E pollFirst()
Deque 复制的描述
public E pollLast()
Deque 复制的描述
public E takeFirst() throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的 takeFirstInterruptedException - 如果在等待时被中断public E takeLast() throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的 takeLastInterruptedException - 如果在等待时被中断public E pollFirst(long timeout, TimeUnit unit) throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的 pollFirsttimeout - 放弃之前等待的时间长度,以 unit 为时间单位unit - 确定如何解释 timeout 参数的 TimeUnit
InterruptedException - 如果在等待时被中断public E pollLast(long timeout, TimeUnit unit) throws InterruptedException
BlockingDeque 复制的描述
BlockingDeque<E> 中的 pollLasttimeout - 放弃之前等待的时间长度,以 unit 为时间单位unit - 确定如何解释 timeout 参数的 TimeUnit
InterruptedException - 如果在等待时被中断public E getFirst()
Deque 复制的描述peekFirst 唯一的不同在于:如果此双端队列为空,它将抛出一个异常。
NoSuchElementException - 如果此双端队列为空public E getLast()
Deque 复制的描述peekLast 唯一的不同在于:如果此双端队列为空,它将抛出一个异常。
NoSuchElementException - 如果此双端队列为空public E peekFirst()
Deque 复制的描述
public E peekLast()
Deque 复制的描述
public boolean removeFirstOccurrence(Object o)
BlockingDeque 复制的描述
BlockingDeque<E> 中的 removeFirstOccurrenceDeque<E> 中的 removeFirstOccurrenceo - 要从此双端队列移除的元素(如果存在)
public boolean removeLastOccurrence(Object o)
BlockingDeque 复制的描述
BlockingDeque<E> 中的 removeLastOccurrenceDeque<E> 中的 removeLastOccurrenceo - 要从此双端队列移除的元素(如果存在)
public boolean add(E e)
offer 方法。
此方法等效于 addLast(E)。
Collection<E> 中的 addBlockingDeque<E> 中的 addBlockingQueue<E> 中的 addDeque<E> 中的 addQueue<E> 中的 addAbstractQueue<E> 中的 adde - 要添加的元素
Collection.add(E) 的规定)
IllegalStateException - 如果此刻由于容量限制而无法添加元素
NullPointerException - 如果指定的元素为 nullpublic boolean offer(E e)
BlockingDeque 复制的描述BlockingDeque.add(E) 方法,后者可能无法插入元素,而只是抛出一个异常。
此方法等效于 offerLast。
e - 要添加的元素
NullPointerException - 如果指定的元素为 nullpublic void put(E e) throws InterruptedException
BlockingDeque 复制的描述此方法等效于 putLast。
BlockingDeque<E> 中的 putBlockingQueue<E> 中的 pute - 要添加的元素
NullPointerException - 如果指定的元素为 null
InterruptedException - 如果在等待时被中断public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException
BlockingDeque 复制的描述此方法等效于 offerLast。
BlockingDeque<E> 中的 offerBlockingQueue<E> 中的 offere - 要添加的元素timeout - 放弃之前等待的时间长度,以 unit 为时间单位unit - 确定如何解释 timeout 参数的 TimeUnit
NullPointerException - 如果指定的元素为 null
InterruptedException - 如果在等待时被中断public E remove()
poll 的不同之处在于:如果此双端队列为空,它将抛出一个异常。
此方法等效于 removeFirst。
NoSuchElementException - 如果此双端队列为空public E poll()
BlockingDeque 复制的描述此方法等效于 Deque.pollFirst()。
public E take() throws InterruptedException
BlockingDeque 复制的描述此方法等效于 takeFirst。
BlockingDeque<E> 中的 takeBlockingQueue<E> 中的 takeInterruptedException - 如果在等待时被中断public E poll(long timeout, TimeUnit unit) throws InterruptedException
BlockingDeque 复制的描述此方法等效于 pollFirst。
BlockingDeque<E> 中的 pollBlockingQueue<E> 中的 polltimeout - 放弃之前要等待的时间长度,用 unit 的时间单位表示unit - 确定如何解释 timeout 参数的 TimeUnit
InterruptedException - 如果在等待时被中断public E element()
peek 的不同之处在于:如果此双端队列为空,它将抛出一个异常。
此方法等效于 getFirst。
NoSuchElementException - 如果此双端队列为空public E peek()
BlockingDeque 复制的描述此方法等效于 peekFirst。
public int remainingCapacity()
注意,不能 总是通过检查 remainingCapacity 断定试图插入元素能否成功,因为可能出现另一个线程即将插入或移除一个元素的情况。
BlockingQueue<E> 中的 remainingCapacitypublic int drainTo(Collection<? super E> c)
BlockingQueue 复制的描述
BlockingQueue<E> 中的 drainToc - 接收传输元素的 collection
UnsupportedOperationException - 如果指定 collection 不支持添加元素
ClassCastException - 如果此队列元素的类不允许将其添加到指定 collection
NullPointerException - 如果指定 collection 为 null
IllegalArgumentException - 如果指定 collection 是此队列,或者此队列元素的某些属性不允许将其添加到指定 collectionpublic int drainTo(Collection<? super E> c, int maxElements)
BlockingQueue 复制的描述
BlockingQueue<E> 中的 drainToc - 接收传输元素的 collectionmaxElements - 传输元素的最大数量
UnsupportedOperationException - 如果指定 collection 不支持添加元素
ClassCastException - 如果此队列元素的类不允许将其添加到指定 collection
NullPointerException - 如果指定 collection 为 null
IllegalArgumentException - 如果指定 collection 是此队列,或者此队列元素的某些属性不允许将其添加到指定 collectionpublic void push(E e)
BlockingDeque 复制的描述此方法等效于 addFirst。
e - 要推入的元素
IllegalStateException - 如果此时由于容量限制而无法添加元素
NullPointerException - 如果指定的元素为 nullpublic E pop()
Deque 复制的描述此方法等效于 Deque.removeFirst()。
NoSuchElementException - 如果此双端队列为空public boolean remove(Object o)
此方法等效于 removeFirstOccurrence。
Collection<E> 中的 removeBlockingDeque<E> 中的 removeBlockingQueue<E> 中的 removeDeque<E> 中的 removeAbstractCollection<E> 中的 removeo - 要从此双端队列移除的元素(如果存在)
public int size()
Collection<E> 中的 sizeBlockingDeque<E> 中的 sizeDeque<E> 中的 sizeAbstractCollection<E> 中的 sizepublic boolean contains(Object o)
Collection<E> 中的 containsBlockingDeque<E> 中的 containsBlockingQueue<E> 中的 containsDeque<E> 中的 containsAbstractCollection<E> 中的 containso - 检查是否包含于此双端队列的对象
public Object[] toArray()
由于此双端队列不维护对返回数组的任何引用,因而它将是“安全的”。(换句话说,此方法必须分配一个新的数组)。因此,调用者可以自由地修改返回的数组。
此方法充当了基于数组的 API 与基于 collection 的 API 之间的桥梁。
Collection<E> 中的 toArrayAbstractCollection<E> 中的 toArraypublic <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> 中的 toArrayAbstractCollection<E> 中的 toArraya - 要用来存储双端队列元素的数组(如果该数组足够大);否则,将为此分配一个具有相同运行时类型的新数组
ArrayStoreException - 如果指定数组的运行时类型不是此双端队列每个元素的运行时类型的超类型
NullPointerException - 如果指定的数组为 nullpublic String toString()
AbstractCollection 复制的描述String.valueOf(Object) 可以将元素转换成字符串。
AbstractCollection<E> 中的 toStringpublic void clear()
Collection<E> 中的 clearAbstractQueue<E> 中的 clearpublic Iterator<E> iterator()
ConcurrentModificationException 的“弱一致”迭代器,能确保遍历迭代器构造后存在的所有元素,并可以(但并不保证)反映构造后的任何修改。
Iterable<E> 中的 iteratorCollection<E> 中的 iteratorBlockingDeque<E> 中的 iteratorDeque<E> 中的 iteratorAbstractCollection<E> 中的 iteratorpublic Iterator<E> descendingIterator()
ConcurrentModificationException 的“弱一致”迭代器,能确保遍历迭代器构造后存在的所有元素,并可以(但并不保证)反映构造后的任何修改。
Deque<E> 中的 descendingIterator
  | 
JavaTM Platform Standard Ed. 6  | 
|||||||||
| 上一个类 下一个类 | 框架 无框架 | |||||||||
| 摘要: 嵌套 | 字段 | 构造方法 | 方法 | 详细信息: 字段 | 构造方法 | 方法 | |||||||||
版权所有 2007 Sun Microsystems, Inc. 保留所有权利。 请遵守许可证条款。另请参阅文档重新分发政策。