ConditionPriorityBlockingQueue

public class ConditionPriorityBlockingQueue
extends Object implements Iterable<T>

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


具有類似 PriorityBlockingQueue 作業的執行緒安全類別,可擷取符合特定條件的物件。

疊代作業也遵守執行緒安全原則,但並不一致。佇列副本會在疊代器建立時建立,並做為疊代目標。如果在疊代期間修改佇列,系統不會擲回 ConcurrentModificationException,但疊代器也不會反映修改後的內容。

另請參閱:

摘要

巢狀類別

class ConditionPriorityBlockingQueue.AlwaysMatch<T>

與任何物件相符的 ConditionPriorityBlockingQueue.IMatcher。 

interface ConditionPriorityBlockingQueue.IMatcher<T>

這個介面用於判斷元素是否符合某種條件。 

公用建構函式

ConditionPriorityBlockingQueue()

建立 ConditionPriorityBlockingQueue

系統會依先進先出 (FIFO) 順序處理元素。

ConditionPriorityBlockingQueue(Comparator<T> c)

建立 ConditionPriorityBlockingQueue

公用方法

boolean add(T addedElement)

將指定元素插入這個佇列。

T addUnique(IMatcher<T> matcher, T object)

Adds a item to this queue, replacing any existing object that matches given condition

void clear()

從這個佇列中移除所有元素。

boolean contains(T object)

判斷物件目前是否包含在這個佇列中。

List<T> getCopy()

取得佇列內容的副本。

Iterator<T> iterator()

T poll(IMatcher<T> matcher)

擷取並移除佇列中最小的 Comparator 元素 T (由提供的 Comparator 元素 T 判斷),其中 matcher.matches(T)true

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

擷取並移除佇列中最小的 Comparator 元素 T (由提供的 Comparator 元素 T 判斷),其中 matcher.matches(T)true

T poll(long timeout, TimeUnit unit)

擷取並移除佇列中最小的 Comparator 元素 T (由提供的 Comparator 元素判斷)。

T poll()

擷取並移除這個佇列的開頭。

boolean remove(T object)

從這個佇列中移除項目。

int size()
T take()

擷取並移除佇列中最小的 Comparator 元素 T (由提供的 Comparator 元素判斷)。

T take(IMatcher<T> matcher)

擷取並移除佇列中的第一個元素 T (其中 matcher.matches(T)true),必要時會等待該元素可用。

公用建構函式

ConditionPriorityBlockingQueue

public ConditionPriorityBlockingQueue ()

建立 ConditionPriorityBlockingQueue

系統會依先進先出順序處理元素。

ConditionPriorityBlockingQueue

public ConditionPriorityBlockingQueue (Comparator<T> c)

建立 ConditionPriorityBlockingQueue

參數
c Comparator:用於排定佇列優先順序的 Comparator

公用方法

新增

public boolean add (T addedElement)

將指定元素插入這個佇列。由於佇列沒有界限,這個方法絕不會封鎖。

參數
addedElement T:要新增的元素

傳回
boolean true

擲回
ClassCastException 如果無法根據優先佇列的排序方式,將指定元素與目前優先佇列中的元素進行比較
NullPointerException 如果指定的元素為空值

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 如果佇列中包含指定物件,則為 truefalse> 否則。

getCopy

public List<T> getCopy ()

取得佇列內容的副本。

傳回
List<T>

疊代器

public Iterator<T> iterator ()

傳回
Iterator<T>

輪詢

public T poll (IMatcher<T> matcher)

擷取並移除佇列中最小的 Comparator 元素 T (由提供的 Comparator 元素 T 判斷),其中 matcher.matches(T)true

參數
matcher IMatcher:用於評估元素的 IMatcher

傳回
T 相符的最小元素,或沒有相符元素時的 null

輪詢

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

擷取並移除佇列中最小的 Comparator 元素 T (由提供的 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 (由提供的 Comparator 元素判斷)。

最多可封鎖 timeout 時間,讓元素可供使用。

參數
timeout long:等待元素可用的時間長度

unit TimeUnit:逾時的 TimeUnit

傳回
T 相符的最小元素,或沒有相符元素時的 null

擲回
InterruptedException

輪詢

public T poll ()

擷取並移除這個佇列的開頭。

傳回
T 這個佇列的開頭,如果佇列為空,則為 null

移除

public boolean remove (T object)

從這個佇列中移除項目。

參數
object T:要移除的物件

傳回
boolean true 如果指定物件已從佇列中移除。false> 否則。

大小

public int size ()

傳回
int 佇列中的元素數

take

public T take ()

擷取並移除佇列中最小的 Comparator 元素 T (由提供的 Comparator 元素判斷)。

無限期封鎖,直到元素可用為止。

傳回
T 這個佇列的開頭

擲回
InterruptedException 等待期間中斷

take

public T take (IMatcher<T> matcher)

擷取並移除佇列中的第一個元素 T (其中 matcher.matches(T)true),必要時會等待該元素可用。

參數
matcher IMatcher:用於評估元素的 IMatcher

傳回
T 相符元素

擲回
InterruptedException 等待期間中斷