-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeam2.java
More file actions
43 lines (33 loc) · 934 Bytes
/
Copy pathTeam2.java
File metadata and controls
43 lines (33 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package hashCodeEquals;
class Team2 {
String city;
String department;
public Team2(String city, String department) {
this.city = city;
this.department = department;
}
@Override
public final boolean equals(Object obj) {
if (obj == this) // same object is passed
return true;
if (!(obj instanceof Object))
return false;
Team2 otherObj = (Team2) obj;
boolean isCurrenyCodeEqual = (this.city == null && otherObj.city == null) || (this.city.equals(otherObj.city));
boolean isDepartmentEqual = (this.department == null && otherObj.department == null)
|| (this.department.equals(otherObj.department));
return isCurrenyCodeEqual && isDepartmentEqual;
}
@Override
public int hashCode() {
super.hashCode();
int result = 17;
if (city != null) {
result = 31 * result + city.hashCode();
}
if (department != null) {
result = 31 * result + department.hashCode();
}
return result;
}
}