import
java.util.*;
import
java.util.concurrent.LinkedBlockingQueue;
import
java.util.concurrent.BlockingQueue;
public
class
GFG {
public
class
Employee {
public
String name;
public
String position;
public
String salary;
Employee(String name, String position, String salary)
{
this
.name = name;
this
.position = position;
this
.salary = salary;
}
@Override
public
String toString()
{
return
"Employee [name="
+ name +
", "
+
"position="
+ position +
", salary="
+ salary +
"]"
;
}
}
public
static
void
main(String[] args)
{
GFG gfg =
new
GFG();
gfg.containsMethodExample();
}
public
void
containsMethodExample()
{
int
capacity =
10
;
BlockingQueue<Employee> BQ
=
new
LinkedBlockingQueue<Employee>(capacity);
HashSet<Employee> collection =
new
HashSet<Employee>();
Employee emp1 =
new
Employee(
"Sachin"
,
"Analyst"
,
"40000"
);
Employee emp2 =
new
Employee(
"Aman"
,
"Developer"
,
"69000"
);
Employee emp3 =
new
Employee(
"Kajal"
,
"Accountant"
,
"39000"
);
BQ.add(emp1);
BQ.add(emp2);
BQ.add(emp3);
System.out.println(
"Before drainTo():"
);
System.out.println(
"No of Elements in Queue is "
+ BQ.size());
System.out.println(
"Elements in Queue is as follows"
);
Iterator<Employee> listOfemp = BQ.iterator();
while
(listOfemp.hasNext())
System.out.println(listOfemp.next());
System.out.println(
"No of Elements in HashSet is "
+ collection.size());
System.out.println(
"Elements in HashSet is as follows:"
);
for
(Employee emp : collection)
System.out.println(emp);
int
noOfElement =
2
;
int
response = BQ.drainTo(collection, noOfElement);
System.out.println(
"\nNo of element passed: "
+ response);
System.out.println(
"\nAfter drainTo():"
);
System.out.println(
"No of Elements in Queue is "
+ BQ.size());
System.out.println(
"Elements in Queue is as follows"
);
listOfemp = BQ.iterator();
while
(listOfemp.hasNext())
System.out.println(listOfemp.next());
System.out.println(
"No of Elements in HashSet is "
+ collection.size());
System.out.println(
"Elements in HashSet is as follows:"
);
for
(Employee emp : collection)
System.out.println(emp);
}
}