import
java.util.Collection;
import
java.util.Iterator;
import
java.util.concurrent.ConcurrentLinkedQueue;
class
ConcurrentLinkedQueueImplmentation<E> {
private
ConcurrentLinkedQueue<E> concurrentLinkedQueue;
public
ConcurrentLinkedQueueImplmentation()
{
concurrentLinkedQueue =
new
ConcurrentLinkedQueue<>();
}
public
ConcurrentLinkedQueueImplmentation(Collection<?
extends
E> c)
{
concurrentLinkedQueue =
new
ConcurrentLinkedQueue<>(c);
}
public
boolean
add(E e)
{
return
concurrentLinkedQueue.add(e);
}
public
boolean
contains(Object o)
{
return
concurrentLinkedQueue.contains(o);
}
public
Iterator<E> iterator()
{
return
concurrentLinkedQueue.iterator();
}
public
boolean
offer(E e)
{
return
concurrentLinkedQueue.offer(e);
}
public
E peek() {
return
concurrentLinkedQueue.peek(); }
public
E poll() {
return
concurrentLinkedQueue.poll(); }
public
boolean
remove(Object o)
{
return
concurrentLinkedQueue.remove(o);
}
public
int
size()
{
return
concurrentLinkedQueue.size();
}
public
Object[] toArray()
{
return
concurrentLinkedQueue.toArray();
}
public
<T> T[] toArray(T[] a)
{
return
concurrentLinkedQueue.toArray(a);
}
}
public
class
GFG {
public
static
void
main(String[] arg)
{
ConcurrentLinkedQueueImplmentation<Integer>
concurrentLinkedQueue
=
new
ConcurrentLinkedQueueImplmentation<
Integer>();
concurrentLinkedQueue.add(
10
);
concurrentLinkedQueue.add(
20
);
concurrentLinkedQueue.add(
30
);
concurrentLinkedQueue.add(
40
);
concurrentLinkedQueue.add(
50
);
System.out.println(
"The elements of the ConcurrentLinkedQueue is:"
);
Iterator<Integer> it
= concurrentLinkedQueue.iterator();
while
(it.hasNext())
{
System.out.print(it.next() +
" "
);
}
System.out.println();
System.out.println(
"Size of the concurrentLinkedQueue is: "
+ concurrentLinkedQueue.size());
System.out.println();
System.out.println(
"The peek element of the concurrentLinkedQueue is: "
+ concurrentLinkedQueue.peek());
System.out.println();
System.out.println(
"The polled element of the concurrentLinkedQueue is: "
+ concurrentLinkedQueue.poll());
System.out.println();
System.out.println(
"Remove 30: "
+ concurrentLinkedQueue.remove(
30
));
System.out.println();
System.out.println(
"The concurrentLinkedQueue contains 40:"
+ concurrentLinkedQueue.contains(
40
));
System.out.println();
System.out.println(
"Size of the concurrentLinkedQueue is: "
+ concurrentLinkedQueue.size());
}
}