import
java.util.Collection;
import
java.util.Iterator;
import
java.util.concurrent.ArrayBlockingQueue;
import
java.util.concurrent.TimeUnit;
public
class
ArrayBlockingQueueImpl<E> {
private
ArrayBlockingQueue<E> arrayBlockingQueue;
public
ArrayBlockingQueueImpl(
int
cap)
{
arrayBlockingQueue =
new
ArrayBlockingQueue<E>(cap);
}
public
ArrayBlockingQueueImpl(
int
cap,
boolean
fair)
{
arrayBlockingQueue
=
new
ArrayBlockingQueue<>(cap, fair);
}
public
ArrayBlockingQueueImpl(
int
cap,
boolean
fair,
Collection<?
extends
E> collection)
{
arrayBlockingQueue =
new
ArrayBlockingQueue<E>(
cap, fair, collection);
}
boolean
add(E e) {
return
arrayBlockingQueue.add(e); }
void
clear() { arrayBlockingQueue.clear(); }
public
boolean
contains(Object o)
{
return
arrayBlockingQueue.contains(o);
}
public
int
drainTo(Collection<?
super
E> c)
{
return
arrayBlockingQueue.drainTo(c);
}
public
int
drainTo(Collection<?
super
E> c,
int
maxElements)
{
return
arrayBlockingQueue.drainTo(c, maxElements);
}
public
Iterator<E> iterator()
{
return
arrayBlockingQueue.iterator();
}
public
boolean
offer(E e)
{
return
arrayBlockingQueue.offer(e);
}
public
boolean
offer(E e,
long
timeout, TimeUnit unit)
throws
InterruptedException
{
return
arrayBlockingQueue.offer(e, timeout, unit);
}
public
E peek() {
return
arrayBlockingQueue.peek(); }
public
E poll() {
return
arrayBlockingQueue.poll(); }
public
E poll(
long
timeout, TimeUnit unit)
throws
InterruptedException
{
return
arrayBlockingQueue.poll(timeout, unit);
}
public
void
put(E e)
throws
InterruptedException
{
arrayBlockingQueue.put(e);
}
public
int
remainingCapacity()
{
return
arrayBlockingQueue.remainingCapacity();
}
public
boolean
remove(Object o)
{
return
arrayBlockingQueue.remove(o);
}
public
int
size() {
return
arrayBlockingQueue.size(); }
public
E take()
throws
InterruptedException
{
return
arrayBlockingQueue.take();
}
public
Object[] toArray()
{
return
arrayBlockingQueue.toArray();
}
public
<T> T[] toArray(T[] a)
{
return
arrayBlockingQueue.toArray(a);
}
public
String toString()
{
return
arrayBlockingQueue.toString();
}
public
static
void
main(String[] args)
{
int
capacity_queue =
10
;
boolean
fair =
true
;
ArrayBlockingQueue<String> queue
=
new
ArrayBlockingQueue<String>(capacity_queue,
fair);
queue.add(
"one"
);
queue.add(
"two"
);
queue.add(
"three"
);
queue.add(
"four"
);
queue.add(
"five"
);
System.out.println(
"ArrayBlockingQueue (when fair policy is true):"
+ queue);
System.out.println(
"Peek element of the queue : "
+ queue.peek());
System.out.println(
"Deleting the element 'five' from the queue : "
+ queue.remove(
"five"
));
System.out.println(
"ArrayBlockingQueue :"
+ queue);
queue.clear();
System.out.println(
"ArrayBlockingQueue after clear operation :"
+ queue);
}
}