ConditionPriorityBlockingQueue
public
class
ConditionPriorityBlockingQueue
extends Object
java.lang.Object | |
↳ | com.android.tradefed.util.ConditionPriorityBlockingQueue<T> |
一个线程安全的类,具有类似 ERROR(/PriorityBlockingQueue)
的操作,可检索与特定条件匹配的对象。
迭代也是线程安全的,但不一致。在创建迭代器时,系统会创建队列的副本,并将该副本用作迭代目标。如果队列在迭代期间被修改,系统不会抛出 ERROR(/ConcurrentModificationException)
,但迭代器也不会反映修改后的内容。
摘要
嵌套类 | |
---|---|
class |
ConditionPriorityBlockingQueue.AlwaysMatch<T>
与任何对象匹配的 |
interface |
ConditionPriorityBlockingQueue.IMatcher<T>
用于确定元素是否符合某种条件的接口。 |
公共构造函数 | |
---|---|
ConditionPriorityBlockingQueue()
创建 元素将按 FIFO 顺序排定优先级。 |
|
ConditionPriorityBlockingQueue(
|
公共方法 | |
---|---|
boolean
|
add(T addedElement)
将指定元素插入此队列。 |
T
|
addUnique(IMatcher<T> matcher, T object)
向此队列添加项,替换与给定条件匹配的任何现有对象 |
void
|
clear()
从此队列中移除所有元素。 |
boolean
|
contains(T object)
确定对象当前是否包含在此队列中。 |
|
getCopy()
获取队列内容的副本。 |
|
iterator()
|
T
|
poll(long timeout, TimeUnit unit)
检索并移除队列中最小(根据队列中提供的 |
T
|
poll(long timeout, TimeUnit unit, IMatcher<T> matcher)
检索并移除队列中值最小的元素(根据队列中提供的 |
T
|
poll(IMatcher<T> matcher)
检索并移除队列中值最小的元素(根据队列中提供的 |
T
|
poll()
检索并移除此队列的头部。 |
boolean
|
remove(T object)
从此队列中移除项。 |
int
|
size()
|
T
|
take()
检索并移除队列中最小(根据队列中提供的 |
T
|
take(IMatcher<T> matcher)
检索并移除队列中第一个元素 T,其中 matcher.matches(T) 为 |
公共构造函数
ConditionPriorityBlockingQueue
public ConditionPriorityBlockingQueue ()
创建 ConditionPriorityBlockingQueue
元素将按 FIFO 顺序排定优先级。
ConditionPriorityBlockingQueue
public ConditionPriorityBlockingQueue (c)
创建 ConditionPriorityBlockingQueue
参数 | |
---|---|
c |
:用于确定队列优先级的 ERROR(/Comparator) 。 |
公共方法
添加
public boolean add (T addedElement)
将指定元素插入此队列。由于队列是无限的,因此此方法永远不会阻塞。
参数 | |
---|---|
addedElement |
T :要添加的元素 |
返回 | |
---|---|
boolean |
true |
抛出 | |
---|---|
ClassCastException |
如果无法根据优先队列的排序规则将指定元素与优先队列中当前的元素进行比较 |
NullPointerException |
如果指定的元素为 null |
addUnique
public T addUnique (IMatcher<T> matcher, T object)
向此队列添加项,替换与给定条件匹配的任何现有对象
参数 | |
---|---|
matcher |
IMatcher :用于评估现有对象的匹配器 |
object |
T :要添加的对象 |
返回 | |
---|---|
T |
被替换的对象,如果不存在,则为 null |
清除
public void clear ()
从此队列中移除所有元素。
包含
public boolean contains (T object)
确定对象当前是否包含在此队列中。
参数 | |
---|---|
object |
T :要查找的对象 |
返回 | |
---|---|
boolean |
如果指定对象包含在队列中,则为 true 。否则为 false> 。 |
getCopy
publicgetCopy ()
获取队列内容的副本。
返回 | |
---|---|
|
iterator
publiciterator ()
返回 | |
---|---|
|
轮询
public T poll (long timeout, TimeUnit unit)
检索并移除队列中最小(根据队列中提供的 ERROR(/Comparator)
元素 T 进行判断)的元素。
最多阻塞 timeout 时间,以等待元素可用。
参数 | |
---|---|
timeout |
long :等待元素可用的时间 |
unit |
TimeUnit :超时的 ERROR(/TimeUnit) |
返回 | |
---|---|
T |
最小匹配元素,如果没有匹配元素,则为 null |
轮询
public T poll (long timeout, TimeUnit unit, IMatcher<T> matcher)
检索并移除队列中值最小的元素(根据队列中提供的 ERROR(/Comparator)
元素 T 进行判断,其中 matcher.matches(T) 为 true
)。
最多阻塞 timeout 时间,以等待元素可用。
参数 | |
---|---|
timeout |
long :等待元素可用的时间 |
unit |
TimeUnit :超时的 ERROR(/TimeUnit) |
matcher |
IMatcher :用于评估元素的 IMatcher |
返回 | |
---|---|
T |
最小匹配元素,如果没有匹配元素,则为 null |
轮询
public T poll (IMatcher<T> matcher)
检索并移除队列中最小值(根据队列中提供的 ERROR(/Comparator)
元素 T 进行判断,其中 matcher.matches(T) 为 true
)。
参数 | |
---|---|
matcher |
IMatcher :用于评估元素的 IMatcher |
返回 | |
---|---|
T |
最小匹配元素,如果没有匹配元素,则为 null |
轮询
public T poll ()
检索并移除此队列的头部。
返回 | |
---|---|
T |
此队列的头部,如果队列为空,则为 null |
移除
public boolean remove (T object)
从此队列中移除项。
参数 | |
---|---|
object |
T :要移除的对象 |
返回 | |
---|---|
boolean |
true ,如果指定对象已从队列中移除。否则为 false> 。 |
size
public int size ()
返回 | |
---|---|
int |
队列中的元素数量 |
拍摄
public T take ()
检索并移除队列中最小(根据队列中提供的 ERROR(/Comparator)
元素 T 进行判断)的元素。
无限期阻塞,直到元素可用为止。
返回 | |
---|---|
T |
此队列的头部 |
抛出 | |
---|---|
InterruptedException |
如果在等待期间被中断 |