條件優先阻塞隊列
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 ( c) ConditionPriorityBlockingQueue ( c) |
公共方法 | |
---|---|
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) 在matcher.matches(T)為 |
T | poll ( IMatcher <T> matcher) 在matcher.matches(T)為 |
T | poll () 檢索並刪除此隊列的頭部。 |
boolean | remove (T object) 從此隊列中刪除一個項目。 |
int | size () |
T | take () 檢索並刪除隊列中的最小值(由提供的 |
T | take ( IMatcher <T> matcher) 檢索並移除隊列中matcher.matches(T)為 |
公共構造函數
條件優先阻塞隊列
public ConditionPriorityBlockingQueue ()元素將按 FIFO 順序排列優先級。
條件優先阻塞隊列
public ConditionPriorityBlockingQueue (c)
創建一個ConditionPriorityBlockingQueue
參數 | |
---|---|
c | ERROR(/Comparator) 。 |
公共方法
添加
public boolean add (T addedElement)
將指定元素插入此隊列。由於隊列是無限的,這個方法永遠不會阻塞。
參數 | |
---|---|
addedElement | T :要添加的元素 |
退貨 | |
---|---|
boolean | true |
投擲 | |
---|---|
| 如果根據優先級隊列的排序,指定元素不能與當前在優先級隊列中的元素進行比較 |
| 如果指定元素為空 |
添加唯一性
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> 否則。 |
獲取副本
publicgetCopy ()
獲取隊列內容的副本。
退貨 | |
---|---|
迭代器
publiciterator ()
退貨 | |
---|---|
輪詢
public T poll (long timeout, TimeUnit unit)
檢索並刪除隊列中的最小值(由提供的ERROR(/Comparator)
元素 T 判斷。
參數 | |
---|---|
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 | 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 | 如果給定對像已從隊列中移除, true 。 false> 否則。 |
尺寸
public int size ()
退貨 | |
---|---|
int | 隊列中元素的數量 |
拿
public T take (IMatcher<T> matcher)
檢索並移除隊列中matcher.matches(T)為true
第一個元素 T ,必要時等待直到該元素可用。
參數 | |
---|---|
matcher | IMatcher :用於評估元素的IMatcher |
退貨 | |
---|---|
T | 匹配的元素 |
投擲 | |
---|---|
| 如果在等待時被打斷 |
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2023-03-30 (世界標準時間)。