|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectsimple.util.BlockingStack<E>
public class BlockingStack<E>
Blocks until the list has an item.
Created: Feb 8, 2010
| Field Summary | |
|---|---|
private boolean |
fixedSize
|
private java.util.Vector<E> |
list
|
| Constructor Summary | |
|---|---|
BlockingStack(int size)
Creates a new fixed size First In Last Out queue of size size. |
|
BlockingStack(int size,
int increment)
Creates a new First In Last Out queue with the initial size size. |
|
| Method Summary | ||
|---|---|---|
boolean |
add(E e)
Attempts to add e to the stack, throwing an exception if the stack is full. |
|
boolean |
addAll(java.util.Collection<? extends E> c)
Adds the collection to the stack if there is enough room. |
|
void |
clear()
|
|
boolean |
contains(java.lang.Object e)
|
|
boolean |
containsAll(java.util.Collection<?> c)
|
|
int |
drainTo(java.util.Collection<? super E> c)
|
|
int |
drainTo(java.util.Collection<? super E> c,
int max)
|
|
E |
element()
Returns the last element added or throws an exception if the stack is empty. |
|
boolean |
isEmpty()
|
|
boolean |
isFull()
Whether the stack is full or not. |
|
java.util.Iterator<E> |
iterator()
|
|
boolean |
offer(E e)
Attempts to add e to the stack. |
|
boolean |
offer(E e,
long timeout,
java.util.concurrent.TimeUnit unit)
Attempts to add e to the stack. |
|
E |
peek()
Returns the last element added or null if the stack is empty. |
|
E |
poll()
Removes and returns the last element added or null if the stack is empty. |
|
E |
poll(long timeout,
java.util.concurrent.TimeUnit unit)
Removes and returns the last element added. |
|
void |
put(E e)
Adds the element to the list, blocking if the stack is full. |
|
int |
remainingCapacity()
Returns the remaining capacity of the stack. |
|
E |
remove()
Removes and returns the last element added. |
|
boolean |
remove(java.lang.Object e)
|
|
boolean |
removeAll(java.util.Collection<?> c)
|
|
boolean |
retainAll(java.util.Collection<?> c)
|
|
int |
size()
|
|
E |
take()
Removes and returns the last element added, blocking if the stack is empty. |
|
java.lang.Object[] |
toArray()
|
|
|
toArray(T[] a)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.util.Collection |
|---|
equals, hashCode |
| Field Detail |
|---|
private final java.util.Vector<E> list
private final boolean fixedSize
| Constructor Detail |
|---|
public BlockingStack(int size)
size.
size - Size of the queue.
public BlockingStack(int size,
int increment)
size.
size - Initial size of the queueincrement - Number of slots to add when full. If negative or zero the number of slots double.| Method Detail |
|---|
public boolean add(E e)
e to the stack, throwing an exception if the stack is full.
add in interface java.util.Collection<E>add in interface java.util.concurrent.BlockingQueue<E>add in interface java.util.Queue<E>e - The element to add.
false if there was an underlying error.
{@link - java.lang.IllegalStateException} if the stack is full.
{@link - java.lang.NullPointerException} if e is null.BlockingQueue.add(java.lang.Object),
offer(Object)public boolean offer(E e)
e to the stack.
offer in interface java.util.concurrent.BlockingQueue<E>offer in interface java.util.Queue<E>e - Element to add.
false if stack is full or there was an underlying error.
{@link - java.lang.NullPointerException} if e is nullBlockingQueue.offer(java.lang.Object),
add(Object),
offer(Object, long, TimeUnit)
public boolean offer(E e,
long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
e to the stack. Will wait the specified time
if the stack is full.
offer in interface java.util.concurrent.BlockingQueue<E>e - Element to add.timeout - Length of time to wait.unit - Units of time to wait.
false if the waited time elapsed and the stack is still full or there was an underlying error.
{@link - java.lang.InterruptedException} if interrupted
{@link - java.lang.NullPointerException} if e is null
java.lang.InterruptedExceptionBlockingQueue.offer(java.lang.Object, long, java.util.concurrent.TimeUnit)
public E poll(long timeout,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException
timeout unit if the stack is empty.
poll in interface java.util.concurrent.BlockingQueue<E>timeout - Amount to waitunit - Units to wait
{@link - java.lang.InterruptedException} if interrupted.
java.lang.InterruptedExceptionBlockingQueue.poll(long, java.util.concurrent.TimeUnit)
public void put(E e)
throws java.lang.InterruptedException
put in interface java.util.concurrent.BlockingQueue<E>{@link - java.lang.InterruptedException} if interrupted.
java.lang.InterruptedExceptionBlockingQueue.put(java.lang.Object)public boolean remove(java.lang.Object e)
remove in interface java.util.Collection<E>remove in interface java.util.concurrent.BlockingQueue<E>
public E take()
throws java.lang.InterruptedException
take in interface java.util.concurrent.BlockingQueue<E>java.lang.InterruptedExceptionBlockingQueue.take(),
peek(),
poll(),
poll(long, TimeUnit)public E element()
element in interface java.util.Queue<E>{@link - java.util.NoSuchElementException} if the stack is empty.Queue.element(),
peek(),
take()public E peek()
peek in interface java.util.Queue<E>Queue.peek(),
element(),
take()public E poll()
poll in interface java.util.Queue<E>Queue.poll(),
remove(),
poll(long, TimeUnit)public E remove()
remove in interface java.util.Queue<E>{@link - java.util.NoSuchElementException} if empty.Queue.remove(),
poll()public int remainingCapacity()
remainingCapacity in interface java.util.concurrent.BlockingQueue<E>BlockingQueue.remainingCapacity()public boolean isFull()
true if the stack is full. Always returns false if the stack is not a fixed size.public boolean isEmpty()
isEmpty in interface java.util.Collection<E>public int size()
size in interface java.util.Collection<E>public void clear()
clear in interface java.util.Collection<E>public boolean addAll(java.util.Collection<? extends E> c)
addAll in interface java.util.Collection<E>true if all were added, false otherwise.Collection.addAll(java.util.Collection)public boolean containsAll(java.util.Collection<?> c)
containsAll in interface java.util.Collection<E>public java.util.Iterator<E> iterator()
iterator in interface java.lang.Iterable<E>iterator in interface java.util.Collection<E>public boolean removeAll(java.util.Collection<?> c)
removeAll in interface java.util.Collection<E>public boolean retainAll(java.util.Collection<?> c)
retainAll in interface java.util.Collection<E>public java.lang.Object[] toArray()
toArray in interface java.util.Collection<E>public <T> T[] toArray(T[] a)
toArray in interface java.util.Collection<E>public boolean contains(java.lang.Object e)
contains in interface java.util.Collection<E>contains in interface java.util.concurrent.BlockingQueue<E>public int drainTo(java.util.Collection<? super E> c)
drainTo in interface java.util.concurrent.BlockingQueue<E>
public int drainTo(java.util.Collection<? super E> c,
int max)
drainTo in interface java.util.concurrent.BlockingQueue<E>
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||