forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAlsoGood.java
More file actions
65 lines (57 loc) · 1.21 KB
/
AlsoGood.java
File metadata and controls
65 lines (57 loc) · 1.21 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class AlsoGood {
private int data;
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + data;
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
return checkEquality(this, obj);
}
private static boolean checkEquality(AlsoGood thiz, Object obj) {
if (thiz.getClass() != obj.getClass())
return false;
AlsoGood that = (AlsoGood)obj;
if (thiz.data != that.data)
return false;
return true;
}
}
class Good2 extends Good2Super<Object> {
private int data;
@Override
public int getData() { return data; }
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + getData();
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
return checkEquality(obj);
}
}
abstract class Good2Super<T> {
protected abstract int getData();
protected boolean checkEquality(Object obj) {
if (this.getClass() != obj.getClass())
return false;
Good2Super that = (Good2Super)obj;
if (this.getData() != that.getData())
return false;
return true;
}
}