import
java.util.*;
class
Employee {
private
String name;
private
int
id;
public
Employee(String name,
int
id)
{
this
.name = name;
this
.id = id;
}
public
int
hashCode()
{
System.out.println(
"In hashcode method"
);
int
hashcode =
0
;
return
hashcode;
}
public
boolean
equals(Object obj)
{
System.out.println(
"In equals method"
);
if
(obj
instanceof
Employee) {
Employee emp = (Employee)obj;
return
(emp.name.equals(
this
.name)
&& emp.id ==
this
.id);
}
else
{
return
false
;
}
}
public
String getName() {
return
name; }
public
void
setName(String name) {
this
.name = name; }
public
int
getId() {
return
id; }
public
void
setId(
int
id) {
this
.id = id; }
public
String toString()
{
return
"Employee Id: "
+ id +
" Name: "
+ name;
}
}
public
class
Duplicate_Value {
public
static
void
main(String a[])
{
LinkedHashMap<Employee, Integer> lhm
=
new
LinkedHashMap<Employee, Integer>();
lhm.put(
new
Employee(
"John"
,
1020
),
1
);
lhm.put(
new
Employee(
"Ravi"
,
1040
),
2
);
lhm.put(
new
Employee(
"Jaya"
,
1030
),
3
);
for
(Map.Entry<Employee, Integer> entry :
lhm.entrySet()) {
System.out.println(entry.getKey() +
"=>"
+ entry.getValue());
}
Employee duplicate =
new
Employee(
"John"
,
1020
);
System.out.println(
"Inserting duplicate record..."
);
lhm.put(duplicate,
4
);
System.out.println(
"After insertion:"
);
for
(Map.Entry<Employee, Integer> entry :
lhm.entrySet()) {
System.out.println(entry.getKey() +
"=>"
+ entry.getValue());
}
}
}