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