My favorites | Sign in
jau
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
package com.googlecode.jau;

/**
* "Real life example"
*/
@JAUEquals
@JAUHashCode
public class RealClass {
private int x = 1;
private int y = 2;
private int z = 3;
private double a = 5.4343;
private String txt = "Testme";

@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final RealClass other = (RealClass) obj;
if (this.x != other.x) {
return false;
}
if (this.y != other.y) {
return false;
}
if (this.z != other.z) {
return false;
}
if (Double.doubleToLongBits(this.a) != Double.doubleToLongBits(other.a)) {
return false;
}
if ((this.txt == null) ? (other.txt != null) : !this.txt.equals(other.txt)) {
return false;
}
return true;
}

@Override
public int hashCode() {
int hash = 7;
hash = 23 * hash + this.x;
hash = 23 * hash + this.y;
hash = 23 * hash + this.z;
hash =
23 * hash +
(int) (Double.doubleToLongBits(this.a) ^
(Double.doubleToLongBits(this.a) >>> 32));
hash = 23 * hash + (this.txt != null ? this.txt.hashCode() : 0);
return hash;
}

@Override
public String toString() {
return super.toString() +
"(x="+x + ", y="+ y + ", z="+z + ", a="+a+", txt=\""+txt+"\")";
}
}

Change log

r69 by Tim.Lebedkov on Feb 8, 2009   Diff
improve performance for equals()
Go to: 
Project members, sign in to write a code review

Older revisions

r60 by Tim.Lebedkov on Feb 4, 2009   Diff
- more tests
All revisions of this file

File info

Size: 1567 bytes, 61 lines
Powered by Google Project Hosting