ConditionPriorityBlockingQueue
public
class
ConditionPriorityBlockingQueue
extends Object
java.lang.Object | |
↳ | com.android.tradefed.util.ConditionPriorityBlockingQueue<T> |
A thread-safe class with ERROR(/PriorityBlockingQueue)
-like operations that can retrieve objects
that match a certain condition.
ERROR(/ConcurrentModificationException)
will not be thrown, but the iterator
will also not reflect the modified contents.
See also:
Summary
Nested classes | |
---|---|
class |
ConditionPriorityBlockingQueue.AlwaysMatch<T>
A |
interface |
ConditionPriorityBlockingQueue.IMatcher<T>
An interface for determining if elements match some sort of condition. |
Public constructors | |
---|---|
ConditionPriorityBlockingQueue()
Creates a |
|
ConditionPriorityBlockingQueue(
Creates a |
Public methods | |
---|---|
boolean
|
add(T addedElement)
Inserts the specified element into this queue. |
T
|
addUnique(IMatcher<T> matcher, T object)
Adds a item to this queue, replacing any existing object that matches given condition |
void
|
clear()
Removes all elements from this queue. |
boolean
|
contains(T object)
Determine if an object is currently contained in this queue. |
|
getCopy()
Get a copy of the contents of the queue. |
|
iterator()
|
T
|
poll(long timeout, TimeUnit unit)
Retrieves and removes the minimum (as judged by the provided |
T
|
poll(long timeout, TimeUnit unit, IMatcher<T> matcher)
Retrieves and removes the minimum (as judged by the provided |
T
|
poll(IMatcher<T> matcher)
Retrieves and removes the minimum (as judged by the provided |
T
|
poll()
Retrieves and removes the head of this queue. |
boolean
|
remove(T object)
Removes an item from this queue. |
int
|
size()
|
T
|
take()
Retrieves and removes the minimum (as judged by the provided |
T
|
take(IMatcher<T> matcher)
Retrieves and removes the first element T in the queue where matcher.matches(T) is
|
Public constructors
ConditionPriorityBlockingQueue
public ConditionPriorityBlockingQueue ()
Creates a ConditionPriorityBlockingQueue
ConditionPriorityBlockingQueue
public ConditionPriorityBlockingQueue (c)
Creates a ConditionPriorityBlockingQueue
Parameters | |
---|---|
c |
: the ERROR(/Comparator) used to prioritize the queue.
|
Public methods
add
public boolean add (T addedElement)
Inserts the specified element into this queue. As the queue is unbounded this method will never block.
Parameters | |
---|---|
addedElement |
T : the element to add |
Returns | |
---|---|
boolean |
true |
Throws | |
---|---|
ClassCastException |
if the specified element cannot be compared with elements currently in the priority queue according to the priority queue's ordering |
NullPointerException |
if the specified element is null |
addUnique
public T addUnique (IMatcher<T> matcher, T object)
Adds a item to this queue, replacing any existing object that matches given condition
Parameters | |
---|---|
matcher |
IMatcher : the matcher to evaluate existing objects |
object |
T : the object to add |
Returns | |
---|---|
T |
the replaced object or null if none exist
|
clear
public void clear ()
Removes all elements from this queue.
contains
public boolean contains (T object)
Determine if an object is currently contained in this queue.
Parameters | |
---|---|
object |
T : the object to find |
Returns | |
---|---|
boolean |
true if given object is contained in queue. false>
otherwise.
|
getCopy
publicgetCopy ()
Get a copy of the contents of the queue.
Returns | |
---|---|
|
iterator
publiciterator ()
Returns | |
---|---|
|
poll
public T poll (long timeout, TimeUnit unit)
Retrieves and removes the minimum (as judged by the provided ERROR(/Comparator)
element T in
the queue.
Parameters | |
---|---|
timeout |
long : the amount of time to wait for an element to become available |
unit |
TimeUnit : the ERROR(/TimeUnit) of timeout |
Returns | |
---|---|
T |
the minimum matched element or null if there are no matching elements
|
poll
public T poll (long timeout, TimeUnit unit, IMatcher<T> matcher)
Retrieves and removes the minimum (as judged by the provided ERROR(/Comparator)
element T in
the queue where matcher.matches(T) is true
.
Parameters | |
---|---|
timeout |
long : the amount of time to wait for an element to become available |
unit |
TimeUnit : the ERROR(/TimeUnit) of timeout |
matcher |
IMatcher : the IMatcher to use to evaluate elements |
Returns | |
---|---|
T |
the minimum matched element or null if there are no matching elements
|
poll
public T poll (IMatcher<T> matcher)
Retrieves and removes the minimum (as judged by the provided ERROR(/Comparator)
element T in
the queue where matcher.matches(T) is true
.
Parameters | |
---|---|
matcher |
IMatcher : the IMatcher to use to evaluate elements |
Returns | |
---|---|
T |
the minimum matched element or null if there are no matching elements
|
poll
public T poll ()
Retrieves and removes the head of this queue.
Returns | |
---|---|
T |
the head of this queue, or null if the queue is empty
|
remove
public boolean remove (T object)
Removes an item from this queue.
Parameters | |
---|---|
object |
T : the object to remove |
Returns | |
---|---|
boolean |
true if given object was removed from queue. false>
otherwise.
|
size
public int size ()
Returns | |
---|---|
int |
the number of elements in queue |
take
public T take ()
Retrieves and removes the minimum (as judged by the provided ERROR(/Comparator)
element T in
the queue.
Returns | |
---|---|
T |
the head of this queue |
Throws | |
---|---|
InterruptedException |
if interrupted while waiting |
take
public T take (IMatcher<T> matcher)
Retrieves and removes the first element T in the queue where matcher.matches(T) is
true
, waiting if necessary until such an element becomes available.
Parameters | |
---|---|
matcher |
IMatcher : the IMatcher to use to evaluate elements |
Returns | |
---|---|
T |
the matched element |
Throws | |
---|---|
InterruptedException |
if interrupted while waiting |
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2019-10-02 UTC.