public class WeakPriorityBlockingQueue<E>
extends java.lang.Object
implements java.io.Serializable
Modifier and Type | Class and Description |
---|---|
private static class |
WeakPriorityBlockingQueue.AbstractElement<E> |
static interface |
WeakPriorityBlockingQueue.Element<E> |
static class |
WeakPriorityBlockingQueue.NaturalElement<E>
natural ordering elements, can be used as container of objects
|
static class |
WeakPriorityBlockingQueue.ReverseElement<E>
reverse ordering elements, can be used as container of objects
|
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList<WeakPriorityBlockingQueue.Element<E>> |
drained |
private java.util.concurrent.Semaphore |
enqueued |
private int |
maxsize |
private java.util.TreeSet<WeakPriorityBlockingQueue.Element<E>> |
queue |
private static long |
serialVersionUID |
Constructor and Description |
---|
WeakPriorityBlockingQueue(int maxsize,
boolean drain)
create a new WeakPriorityBlockingQueue
all elements in the stack are not ordered by their insert order but by a given element weight
weights that are preferred are returned first when a pop from the stack is made
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
clear the queue
|
WeakPriorityBlockingQueue.Element<E> |
element(int position)
all objects that have been returned by poll or take are stored in a back-up list
where they can be retrieved afterward.
|
WeakPriorityBlockingQueue.Element<E> |
element(int position,
long time)
retrieve an element from the drained queue but wait until a timeout
until returning null when no element will be available within the time
from the input queue
|
boolean |
isEmpty()
test if the queue is empty
|
java.util.Iterator<WeakPriorityBlockingQueue.Element<E>> |
iterator()
iterate over all elements available.
|
private java.util.ArrayList<WeakPriorityBlockingQueue.Element<E>> |
list()
return all entries as they would be retrievable with element()
|
java.util.ArrayList<WeakPriorityBlockingQueue.Element<E>> |
list(int count)
return the specific amount of entries as they would be retrievable with element()
if count is < 0 then all elements are taken
the returned list is not cloned from the internal list and shall not be modified in any way (read-only)
|
static void |
main(java.lang.String[] args) |
WeakPriorityBlockingQueue.Element<E> |
peek()
return the element with the smallest weight, but do not remove it
|
WeakPriorityBlockingQueue.Element<E> |
poll()
return the element with the smallest weight and remove it from the stack
|
WeakPriorityBlockingQueue.Element<E> |
poll(long timeout)
Retrieves and removes the head of this queue, waiting if necessary
up to the specified wait time if no elements are present on this queue.
|
void |
put(WeakPriorityBlockingQueue.Element<E> element)
put a element on the stack using a order of the weight
elements that had been on the stack cannot be put in again,
they are checked against the drained list
|
int |
sizeAvailable()
get the number of elements that are available for retrieval
this is a combined number of sizeQueue() and sizeDrained();
|
int |
sizeDrained()
get the number of elements that had been drained so far and are waiting
in a list to get enumerated with element()
|
int |
sizeQueue()
get the number of elements in the queue, waiting to be removed with take() or poll()
|
private WeakPriorityBlockingQueue.Element<E> |
takeUnsafe() |
private static final long serialVersionUID
private final java.util.TreeSet<WeakPriorityBlockingQueue.Element<E>> queue
private final java.util.concurrent.Semaphore enqueued
private final java.util.ArrayList<WeakPriorityBlockingQueue.Element<E>> drained
private int maxsize
public WeakPriorityBlockingQueue(int maxsize, boolean drain)
maxsize
- the maximum size of the stack. When the stack exceeds this number, then entries are removedpublic void clear()
public boolean isEmpty()
public int sizeQueue()
public int sizeDrained()
public int sizeAvailable()
public void put(WeakPriorityBlockingQueue.Element<E> element)
element
- the element (must have a equals() method)weight
- the weight of the elementremove
- - the rating of the element that shall be removed in case that the stack has an size overflowpublic WeakPriorityBlockingQueue.Element<E> poll()
public WeakPriorityBlockingQueue.Element<E> poll(long timeout) throws java.lang.InterruptedException
timeout
- milliseconds until timeoutjava.lang.InterruptedException
private WeakPriorityBlockingQueue.Element<E> takeUnsafe()
public WeakPriorityBlockingQueue.Element<E> peek()
public WeakPriorityBlockingQueue.Element<E> element(int position)
position
- inside the drained queuepublic WeakPriorityBlockingQueue.Element<E> element(int position, long time) throws java.lang.InterruptedException
position
- inside the drained queuetime
- the timeoutjava.lang.InterruptedException
public java.util.ArrayList<WeakPriorityBlockingQueue.Element<E>> list(int count)
count
- private java.util.ArrayList<WeakPriorityBlockingQueue.Element<E>> list()
public java.util.Iterator<WeakPriorityBlockingQueue.Element<E>> iterator()
public static void main(java.lang.String[] args)