条件优先级阻塞队列

public class ConditionPriorityBlockingQueue
extends Object

java.lang.Object
com.android.tradefed.util.ConditionPriorityBlockingQueue<T>


具有类似ERROR(/PriorityBlockingQueue)操作的线程安全类,可以检索与特定条件匹配的对象。

迭代也是线程安全的,但不一致。队列的副本是在迭代器创建时创建的,并且该副本用作迭代目标。如果队列在迭代过程中被修改,不会抛出ERROR(/ConcurrentModificationException) ,但迭代器也不会反映修改的内容。

概括

嵌套类

class ConditionPriorityBlockingQueue.AlwaysMatch <T>

与任何对象匹配的ConditionPriorityBlockingQueue.IMatcher

interface ConditionPriorityBlockingQueue.IMatcher <T>

用于确定元素是否符合某种条件的接口。

公共构造函数

ConditionPriorityBlockingQueue ()

创建ConditionPriorityBlockingQueue

元素将按 FIFO 顺序排列优先级。

ConditionPriorityBlockingQueue ( c) ConditionPriorityBlockingQueue ( c)

创建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)

检索并删除最小值(由队列中提供的ERROR(/Comparator)元素 T 判断)。

T poll (long timeout, TimeUnit unit, IMatcher <T> matcher)

检索并删除队列中matcher.matches(T)true最小值(根据队列中提供的ERROR(/Comparator)元素 T 进行判断)。

T poll ( IMatcher <T> matcher)

检索并删除队列中matcher.matches(T)true最小值(根据队列中提供的ERROR(/Comparator)元素 T 进行判断)。

T poll ()

检索并删除此队列的头部。

boolean remove (T object)

从此队列中删除一个项目。

int size ()
T take ()

检索并删除最小值(由队列中提供的ERROR(/Comparator)元素 T 判断)。

T take ( IMatcher <T> matcher)

检索并删除队列中matcher.matches(T)true第一个元素 T ,如有必要,则等待直到该元素可用。

公共构造函数

条件优先级阻塞队列

public ConditionPriorityBlockingQueue ()

创建ConditionPriorityBlockingQueue

元素将按 FIFO 顺序排列优先级。

条件优先级阻塞队列

public ConditionPriorityBlockingQueue ( c)

创建ConditionPriorityBlockingQueue

参数
c :用于确定队列优先级的ERROR(/Comparator)

公共方法

添加

public boolean add (T addedElement)

将指定元素插入此队列。由于队列是无界的,因此该方法永远不会阻塞。

参数
addedElement T :要添加的元素

退货
boolean true

投掷
ClassCastException如果指定的元素无法根据优先级队列的排序与优先级队列中当前的元素进行比较
NullPointerException如果指定元素为空

添加唯一

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如果给定对象包含在队列中,则为truefalse>否则。

获取副本

public  getCopy ()

获取队列内容的副本。

退货

迭代器

public  iterator ()

退货

轮询

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)

检索并删除队列中matcher.matches(T)true最小值(根据队列中提供的ERROR(/Comparator)元素 T 进行判断)。

阻止元素变为可用的timeout时间。

参数
timeout long :等待元素变得可用的时间量

unit TimeUnit : 超时的ERROR(/TimeUnit)

matcher IMatcher :用于评估元素的IMatcher

退货
T最小匹配元素,如果没有匹配元素则为null

轮询

public T poll (IMatcher<T> matcher)

检索并删除队列中matcher.matches(T)true最小值(根据队列中提供的ERROR(/Comparator)元素 T 进行判断)。

参数
matcher IMatcher :用于评估元素的IMatcher

退货
T最小匹配元素,如果没有匹配元素则为null

轮询

public T poll ()

检索并删除此队列的头部。

退货
T该队列的头部,如果队列为空则为null

消除

public boolean remove (T object)

从此队列中删除一个项目。

参数
object T :要删除的对象

退货
boolean如果给定对象已从队列中删除,则为truefalse>否则。

尺寸

public int size ()

退货
int队列中元素的数量

public T take ()

检索并删除最小值(由队列中提供的ERROR(/Comparator)元素 T 判断)。

无限期地阻止某个元素变得可用。

退货
T这个队列的头

投掷
InterruptedException如果在等待时被打扰

public T take (IMatcher<T> matcher)

检索并删除队列中matcher.matches(T)true第一个元素 T ,如有必要,则等待直到该元素可用。

参数
matcher IMatcher :用于评估元素的IMatcher

退货
T匹配的元素

投掷
InterruptedException如果在等待时被打扰