import
java.util.Collection;
import
java.util.Iterator;
import
java.util.concurrent.LinkedBlockingQueue;
import
java.util.concurrent.TimeUnit;
public
class
BlockingQueue<E> {
private
LinkedBlockingQueue<E> q;
public
BlockingQueue()
{
q =
new
LinkedBlockingQueue<E>();
}
public
BlockingQueue(Collection<?
extends
E> c)
{
q =
new
LinkedBlockingQueue<E>(c);
}
public
BlockingQueue(
int
size)
{
q =
new
LinkedBlockingQueue<E>(size);
}
public
boolean
contains(Object o)
{
return
q.contains(o);
}
public
int
drainTo(Collection<?
super
E> c)
{
return
q.drainTo(c);
}
public
int
drainTo(Collection<?
super
E> c,
int
maxEle)
{
return
q.drainTo(c, maxEle);
}
public
Iterator<E> iterator() {
return
q.iterator(); }
void
clear() { q.clear(); }
public
boolean
offer(E e) {
return
q.offer(e); }
public
boolean
offer(E e,
long
timeout, TimeUnit unit)
throws
InterruptedException
{
return
q.offer(e, timeout, unit);
}
public
E peek() {
return
q.peek(); }
public
E poll() {
return
q.poll(); }
public
E poll(
long
tout, TimeUnit un)
throws
InterruptedException
{
return
q.poll(tout, un);
}
public
int
remainingCapacity()
{
return
q.remainingCapacity();
}
public
boolean
remove(Object o) {
return
q.remove(o); }
public
int
size() {
return
q.size(); }
public
void
put(E e)
throws
InterruptedException
{
q.put(e);
}
public
E take()
throws
InterruptedException
{
return
q.take();
}
public
Object[] toArray() {
return
q.toArray(); }
public
<T> T[] toArray(T[] a) {
return
q.toArray(a); }
public
String toString() {
return
q.toString(); }
public
static
void
main(String[] args)
{
BlockingQueue<Integer> q
=
new
BlockingQueue<Integer>();
try
{
q.put(
1
);
q.put(
2
);
q.put(
3
);
}
catch
(InterruptedException e) {
e.printStackTrace();
}
System.out.println(
"The elements of the LinkedBlockingQueue is "
);
Iterator<Integer> i = q.iterator();
while
(i.hasNext()) {
System.out.print(i.next() +
"\t"
);
}
System.out.println();
System.out.println(
"The remaining capacity is "
+ q.remainingCapacity());
System.out.println(
"3 removed "
+ q.remove(
3
));
q.offer(
6
);
q.offer(
7
);
System.out.println(
"The peak element of the LinkedBlockingQueue is "
+ q.peek());
System.out.println(
"The peak element of the LinkedBlockingQueue is "
+ q.poll());
System.out.println(
"The LinkedBlockingQueue contains 4 :"
+ q.contains(
4
));
System.out.println(
"The LinkedBlockingQueue contains 1 :"
+ q.contains(
1
));
System.out.println(
"The size of the LinkedBlockingQueue is "
+ q.size());
System.out.println(q);
}
}