E
-元素举行此集合中的类型
public class LinkedBlockingDeque<E> extends AbstractQueue<E> implements BlockingDeque<E>, Serializable
可选的容量绑定构造函数参数作为防止过度扩展的一种方法。的能力,如果没有指定,等于Integer.MAX_VALUE
。连接节点动态创建在每次插入除非这会带来deque以上容量。
大多数运行在恒定的时间(忽略时间花费的阻塞)。除了remove
,removeFirstOccurrence
,removeLastOccurrence
,contains
,iterator.remove()
,和批量操作,所有这一切都运行在线性时间。
这个类和它的迭代器实现所有的可选方法的Collection
和Iterator
接口。
这个班的一员 Java Collections Framework。
Constructor and Description |
---|
LinkedBlockingDeque()
创建一个容量
Integer.MAX_VALUE
LinkedBlockingDeque 。
|
LinkedBlockingDeque(Collection<? extends E> c)
创建一个容量
Integer.MAX_VALUE
LinkedBlockingDeque ,最初包含元素的集合,加入集合的迭代器遍历顺序。
|
LinkedBlockingDeque(int capacity)
创建一个与给定的
LinkedBlockingDeque (固定的)能力。
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E e)
插入指定元素在这个队列最后除非它违背了容量限制。
|
void |
addFirst(E e)
插入指定元素在队列前面是否有可能立即这样做不违反容量限制,抛出一个
IllegalStateException 如果没有空间是可用的。
|
void |
addLast(E e)
插入指定元素在这个队列的最后如果可能立即这样做不违反容量限制,抛出一个
IllegalStateException 如果没有空间是可用的。
|
void |
clear()
自动删除所有的从这个容器元素。
|
boolean |
contains(Object o)
如果这两
true 返回包含指定的元素。
|
Iterator<E> |
descendingIterator()
返回在反向顺序在deque容器元素的迭代器。
|
int |
drainTo(Collection<? super E> c)
从这个队列中删除所有可用的元素,并将它们添加到给定的集合中。
|
int |
drainTo(Collection<? super E> c, int maxElements)
从这个队列中移除给定数量的可用元素,并将它们添加到给定的集合中。
|
E |
element()
检索,但不删除,这代表的deque队列的头部。
|
E |
getFirst()
检索,但不删除该deque容器的第一个元素。
|
E |
getLast()
检索,但不删除该队列的最后一个元素。
|
Iterator<E> |
iterator()
返回以正确的顺序在deque容器元素的迭代器。
|
boolean |
offer(E e)
插入指定元素为代表的deque队列(换句话说,在这个队列尾)如果可能立即这样做不违反容量限制,还
true 在成功和
false 如果没有空间是可用的。
|
boolean |
offer(E e, long timeout, TimeUnit unit)
插入指定元素为代表的deque队列(换句话说,在这个队列的尾部),等待到指定的等待时间,如果空间成为必要。
|
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()
检索,但不删除,这代表的deque队列的头部(换句话说,这个容器的第一个元素),或返回
null 如果队列是空的。
|
E |
peekFirst()
检索,但不删除该deque容器的第一个元素,或返回
null 如果队列是空的。
|
E |
peekLast()
检索,但不删除该队列的最后一个元素,或返回
null 如果队列是空的。
|
E |
poll()
检索并移除该deque表示队列的头部(换句话说,这个容器的第一个元素),或返回
null 如果队列是空的。
|
E |
poll(long timeout, TimeUnit unit)
检索并移除该deque表示队列的头部(换句话说,这个容器的第一个元素),等待到指定的等待时间,如果一个元素成为必要。
|
E |
pollFirst()
检索并移除此队列的第一个元素,或返回
null 如果队列是空的。
|
E |
pollFirst(long timeout, TimeUnit unit)
检索并移除此队列的第一个元素,等待到指定的等待时间,如果一个元素成为必要。
|
E |
pollLast()
检索并移除此队列的最后一个元素,或返回
null 如果队列是空的。
|
E |
pollLast(long timeout, TimeUnit unit)
检索并移除此队列的最后一个元素,等待到指定的等待时间,如果一个元素成为必要。
|
E |
pop()
从这个弹出堆栈队列代表元素。
|
void |
push(E e)
将一个元素到该deque表示堆栈(换句话说,在这个队列的头)如果可能立即这样做不违反容量限制,抛出一个
IllegalStateException 如果没有空间是可用的。
|
void |
put(E e)
插入指定元素为代表的deque队列(换句话说,在这个队列的尾部),如果空间成为提供必要的等待。
|
void |
putFirst(E e)
在这个队列的前面插入指定元素,如果空间成为提供必要的等待。
|
void |
putLast(E e)
在这个队列的末尾插入指定元素,如果空间成为提供必要的等待。
|
int |
remainingCapacity()
返回,这的确可以理想的附加元素的数目(在内存或资源限制的情况下)接受无阻塞。
|
E |
remove()
检索并移除该deque队列的头代表。
|
boolean |
remove(Object o)
删除第一个出现的指定元素从这个队列。
|
E |
removeFirst()
检索并移除此队列的第一个元素。
|
boolean |
removeFirstOccurrence(Object o)
删除第一个出现的指定元素从这个队列。
|
E |
removeLast()
检索并移除此队列的最后一个元素。
|
boolean |
removeLastOccurrence(Object o)
移除指定元素的最后出现从这个队列。
|
int |
size()
返回该容器元素的数量。
|
Spliterator<E> |
spliterator()
返回在deque容器元素的
Spliterator 。
|
E |
take()
检索并移除该deque表示队列的头部(换句话说,这个容器的第一个元素),必要时可用等待直到元。
|
E |
takeFirst()
检索并移除此队列的第一个元素,如果有必要,直到一个元素可用等。
|
E |
takeLast()
检索并移除此队列的最后一个元素,如果有必要,直到一个元素可用等。
|
Object[] |
toArray()
返回一个数组包含所有在这个容器的元素,以正确的顺序(从第一个到最后一个元素)。
|
<T> T[] |
toArray(T[] a)
返回一个数组包含所有在这个容器的元素,以正确的顺序;返回数组的运行时类型为指定数组。
|
String |
toString()
返回此集合的字符串表示形式。
|
addAll
containsAll, isEmpty, removeAll, retainAll
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addAll, containsAll, equals, hashCode, isEmpty, parallelStream, removeAll, removeIf, retainAll, stream
public LinkedBlockingDeque()
Integer.MAX_VALUE
LinkedBlockingDeque
。
public LinkedBlockingDeque(int capacity)
LinkedBlockingDeque
(固定的)能力。
capacity
-该deque容器的容量
IllegalArgumentException
-如果
capacity
小于1
public LinkedBlockingDeque(Collection<? extends E> c)
Integer.MAX_VALUE
LinkedBlockingDeque
,最初包含元素的集合,加入集合的迭代器遍历顺序。
c
-最初包含元素的集合
NullPointerException
-如果指定集合或其任何元素都是空的
public void addFirst(E e)
BlockingDeque
IllegalStateException
如果没有空间是可用的。使用容量限制容器时,它是通常最好使用
offerFirst
。
addFirst
接口
BlockingDeque<E>
addFirst
接口
Deque<E>
e
-元素添加
IllegalStateException
NullPointerException
-如果指定元素为null
public void addLast(E e)
BlockingDeque
IllegalStateException
如果没有空间是可用的。使用容量限制容器时,它是通常最好使用
offerLast
。
addLast
接口
BlockingDeque<E>
addLast
接口
Deque<E>
e
-元素添加
IllegalStateException
NullPointerException
-如果指定元素为null
public boolean offerFirst(E e)
BlockingDeque
true
在成功和
false
如果没有空间是可用的。使用容量限制队列时,这种方法是最好的
addFirst
方法,可不能只通过抛出异常,插入一个元素。
offerFirst
接口
BlockingDeque<E>
offerFirst
接口
Deque<E>
e
-元素添加
true
如果元素被添加到这个容器,其他
false
NullPointerException
-如果指定元素为null
public boolean offerLast(E e)
BlockingDeque
true
在成功和
false
如果没有空间是可用的。使用容量限制队列时,这种方法是最好的
addLast
方法,可不能只通过抛出异常,插入一个元素。
offerLast
接口
BlockingDeque<E>
offerLast
接口
Deque<E>
e
-元素添加
true
如果元素被添加到这个容器,其他
false
NullPointerException
-如果指定元素为null
public void putFirst(E e) throws InterruptedException
BlockingDeque
putFirst
接口
BlockingDeque<E>
e
-元素添加
NullPointerException
-如果指定元素为null
InterruptedException
如果中断等待
public void putLast(E e) throws InterruptedException
BlockingDeque
putLast
接口
BlockingDeque<E>
e
-元素添加
NullPointerException
-如果指定元素为null
InterruptedException
如果中断等待
public boolean offerFirst(E e, long timeout, TimeUnit unit) throws InterruptedException
BlockingDeque
offerFirst
接口
BlockingDeque<E>
e
-元素添加
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
true
如果成功,或
false
如果指定的等待时间过去之前可用空间
NullPointerException
-如果指定元素为null
InterruptedException
如果中断等待
public boolean offerLast(E e, long timeout, TimeUnit unit) throws InterruptedException
BlockingDeque
offerLast
接口
BlockingDeque<E>
e
-元素添加
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
true
如果成功,或
false
如果指定的等待时间过去之前可用空间
NullPointerException
-如果指定元素为null
InterruptedException
如果中断等待
public E removeFirst()
Deque
pollFirst
仅在于它抛出一个异常,如果这个容器是空的。
removeFirst
接口
Deque<E>
NoSuchElementException
-如果这队列是空的
public E removeLast()
Deque
pollLast
仅在于它抛出一个异常,如果这个容器是空的。
removeLast
接口
Deque<E>
NoSuchElementException
-如果这队列是空的
public E takeFirst() throws InterruptedException
BlockingDeque
takeFirst
接口
BlockingDeque<E>
InterruptedException
如果中断等待
public E takeLast() throws InterruptedException
BlockingDeque
takeLast
接口
BlockingDeque<E>
InterruptedException
如果中断等待
public E pollFirst(long timeout, TimeUnit unit) throws InterruptedException
BlockingDeque
pollFirst
接口
BlockingDeque<E>
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
null
如果指定的等待时间过去之前一个元素是可用的
InterruptedException
如果中断等待
public E pollLast(long timeout, TimeUnit unit) throws InterruptedException
BlockingDeque
pollLast
接口
BlockingDeque<E>
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
null
如果指定的等待时间过去之前一个元素是可用的
InterruptedException
如果中断等待
public E getFirst()
Deque
peekFirst
仅在于它抛出一个异常,如果这个容器是空的。
getFirst
接口
Deque<E>
NoSuchElementException
-如果这队列是空的
public E getLast()
Deque
peekLast
仅在于它抛出一个异常,如果这个容器是空的。
getLast
接口
Deque<E>
NoSuchElementException
-如果这队列是空的
public boolean removeFirstOccurrence(Object o)
BlockingDeque
o.equals(e)
第一单元
e
(如果这样一个元素存在)。如果这两
true
返回包含指定元素(或等价地,如果调用的结果这的确改变了)。
removeFirstOccurrence
接口
BlockingDeque<E>
removeFirstOccurrence
接口
Deque<E>
o
元要从队列移除,如果存在
true
如果元素是作为一个结果,这叫删除
public boolean removeLastOccurrence(Object o)
BlockingDeque
o.equals(e)
移除最后一个元素
e
(如果这样一个元素存在)。如果这两
true
返回包含指定元素(或等价地,如果调用的结果这的确改变了)。
removeLastOccurrence
接口
BlockingDeque<E>
removeLastOccurrence
接口
Deque<E>
o
元要从队列移除,如果存在
true
如果元素是作为一个结果,这叫删除
public boolean add(E e)
offer
。
这种方法相当于addLast(E)
。
add
接口
Collection<E>
add
接口
BlockingDeque<E>
add
接口
BlockingQueue<E>
add
接口
Deque<E>
add
接口
Queue<E>
add
方法重写,继承类
AbstractQueue<E>
e
-元素添加
Collection.add(E)
指定)
IllegalStateException
NullPointerException
-如果指定元素为null
public boolean offer(E e)
BlockingDeque
true
在成功和
false
如果没有空间是可用的。使用容量限制队列时,这种方法是最好的
BlockingDeque.add(E)
方法,可不能只通过抛出异常,插入一个元素。
这种方法相当于offerLast
。
offer
接口
BlockingDeque<E>
offer
接口
BlockingQueue<E>
offer
接口
Deque<E>
offer
接口
Queue<E>
e
-元素添加
true
如果元素被添加到这个队列,否则
false
NullPointerException
-如果指定元素为null
public void put(E e) throws InterruptedException
BlockingDeque
这种方法相当于putLast
。
put
接口
BlockingDeque<E>
put
接口
BlockingQueue<E>
e
-元素添加
NullPointerException
-如果指定元素为null
InterruptedException
如果中断等待
public boolean offer(E e, long timeout, TimeUnit unit) throws InterruptedException
BlockingDeque
这种方法相当于offerLast
。
offer
接口
BlockingDeque<E>
offer
接口
BlockingQueue<E>
e
-元素添加
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
true
如果元素被添加到这个容器,其他
false
NullPointerException
-如果指定元素为null
InterruptedException
如果中断等待
public E remove()
poll
仅在于它抛出一个异常,如果这个容器是空的。
这种方法相当于removeFirst
。
remove
接口
BlockingDeque<E>
remove
接口
Deque<E>
remove
接口
Queue<E>
remove
方法重写,继承类
AbstractQueue<E>
NoSuchElementException
-如果这队列是空的
public E poll()
BlockingDeque
null
如果队列是空的。
这种方法相当于Deque.pollFirst()
。
public E take() throws InterruptedException
BlockingDeque
这种方法相当于takeFirst
。
take
接口
BlockingDeque<E>
take
接口
BlockingQueue<E>
InterruptedException
如果中断等待
public E poll(long timeout, TimeUnit unit) throws InterruptedException
BlockingDeque
这种方法相当于pollFirst
。
poll
接口
BlockingDeque<E>
poll
接口
BlockingQueue<E>
timeout
-多久才放弃等待,在单位
unit
unit
-
TimeUnit
确定如何解释
timeout
参数
null
如果指定的等待时间过去之前一个元素是可用的
InterruptedException
如果中断等待
public E element()
element
接口
BlockingDeque<E>
element
接口
Deque<E>
element
接口
Queue<E>
element
方法重写,继承类
AbstractQueue<E>
NoSuchElementException
-如果这队列是空的
public E peek()
BlockingDeque
null
如果队列是空的。
这种方法相当于peekFirst
。
public int remainingCapacity()
size
。
注意,你不能总是告诉如果试图插入一个元素将通过检查remainingCapacity
成功因为它可能的情况是,另一个线程要插入或删除一个元素。
remainingCapacity
接口
BlockingQueue<E>
public int drainTo(Collection<? super E> c)
BlockingQueue
c
添加元素可能会导致元素在没有遭遇过失败,或集合时相关的异常被抛出。试图排队列本身造成
IllegalArgumentException
。此外,如果指定的收集是在操作进行修改此操作的行为是未定义的。
drainTo
接口
BlockingQueue<E>
c
-收集传递元素
UnsupportedOperationException
如果添加元素不按指定集合的支持
ClassCastException
-如果该队列的元素类型阻止其加入指定集合
NullPointerException
-如果指定集合为空
IllegalArgumentException
-如果指定集合的队列,该队列或一个元素的一些特性可以防止它被添加到指定的集合
public int drainTo(Collection<? super E> c, int maxElements)
BlockingQueue
c
添加元素可能会导致元素在没有遭遇过失败,或集合时相关的异常被抛出。试图排队列本身造成
IllegalArgumentException
。此外,当操作正在进行中时,此操作的行为是不确定的,如果指定的集合被修改了。
drainTo
接口
BlockingQueue<E>
c
-收集传递元素
maxElements
-元素的最大数量的转移
UnsupportedOperationException
如果添加元素不按指定集合的支持
ClassCastException
-如果该队列的元素类型阻止其加入指定集合
NullPointerException
-如果指定集合为空
IllegalArgumentException
-如果指定集合的队列,该队列或一个元素的一些特性可以防止它被添加到指定的集合
public void push(E e)
BlockingDeque
IllegalStateException
如果没有空间是可用的。
这种方法相当于addFirst
。
push
接口
BlockingDeque<E>
push
接口
Deque<E>
e
-元推
IllegalStateException
NullPointerException
-如果指定元素为null
public E pop()
Deque
这种方法相当于Deque.removeFirst()
。
pop
接口
Deque<E>
NoSuchElementException
-如果这队列是空的
public boolean remove(Object o)
e
这样
o.equals(e)
(如果这种元素的存在)。如果这两
true
返回包含指定元素(或等价地,如果调用的结果这的确改变了)。
这种方法相当于removeFirstOccurrence
。
remove
接口
Collection<E>
remove
接口
BlockingDeque<E>
remove
接口
BlockingQueue<E>
remove
接口
Deque<E>
remove
方法重写,继承类
AbstractCollection<E>
o
元要从队列移除,如果存在
true
如果调用的结果这的确改变了
public int size()
size
接口
Collection<E>
size
接口
BlockingDeque<E>
size
接口
Deque<E>
size
方法重写,继承类
AbstractCollection<E>
public boolean contains(Object o)
true
返回包含指定的元素。更正式地说,返回
true
当且仅当这个容器包含至少一个元素
e
这样
o.equals(e)
。
contains
接口
Collection<E>
contains
接口
BlockingDeque<E>
contains
接口
BlockingQueue<E>
contains
接口
Deque<E>
contains
方法重写,继承类
AbstractCollection<E>
o
对象进行检查在deque容器
true
包含指定的元素
public Object[] toArray()
返回的数组将“安全”,没有提到它的容器保持。(换句话说,这种方法必须分配一个新的数组)。因此,调用方可以自由修改返回的数组。
此方法作为基于数组和基于集合的原料药之间的桥梁。
toArray
接口
Collection<E>
toArray
方法重写,继承类
AbstractCollection<E>
public <T> T[] toArray(T[] a)
如果这的确符合指定数组中剩余的空间(即数组有比这更多的元素,deque)阵列中的队列立即结束后的元素设置为null
。
像toArray()
方法,该方法作为之间的桥梁,基于阵列和基于集合API。此外,该方法允许对输出数组的运行时类型的精确控制,并在某些情况下,可用于节省分配成本。
假设x
是deque容器称为只包含字符串。下面的代码可以用来倾倒容器为新分配的数组String
:
String[] y = x.toArray(new String[0]);
注意
toArray(new Object[0])
是相同的功能,
toArray()
。
toArray
接口
Collection<E>
toArray
方法重写,继承类
AbstractCollection<E>
T
-数组的运行时类型包含集合
a
-为该容器的元素被存储数组,如果它足够大;否则,一个新的运行时类型相同的数组分配给这个目的
ArrayStoreException
-如果指定数组的运行时类型不是超在该队列的每个元素运行时类型
NullPointerException
-如果指定的数组是空的
public String toString()
AbstractCollection
String.valueOf(Object)
。
toString
方法重写,继承类
AbstractCollection<E>
public void clear()
clear
接口
Collection<E>
clear
方法重写,继承类
AbstractQueue<E>
public Iterator<E> iterator()
返回的迭代器是weakly consistent。
iterator
接口
Iterable<E>
iterator
接口
Collection<E>
iterator
接口
BlockingDeque<E>
iterator
接口
Deque<E>
iterator
方法重写,继承类
AbstractCollection<E>
public Iterator<E> descendingIterator()
返回的迭代器是weakly consistent。
descendingIterator
接口
Deque<E>
public Spliterator<E> spliterator()
Spliterator
。
返回的spliterator是weakly consistent。
报告的Spliterator
Spliterator.CONCURRENT
,Spliterator.ORDERED
,和Spliterator.NONNULL
。
spliterator
接口
Iterable<E>
spliterator
接口
Collection<E>
Spliterator
trySplit
允许有限的并行实现。
Spliterator
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.