條件優先權阻塞佇列

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如果在等待時被打擾