01: package org.drools;
02:
03: public class PersonWithEquals {
04:
05: private String name;
06: private int age;
07:
08: public PersonWithEquals() {
09: }
10:
11: public PersonWithEquals(String name, int age) {
12: super ();
13: this .name = name;
14: this .age = age;
15: }
16:
17: public int getAge() {
18: return age;
19: }
20:
21: public void setAge(int age) {
22: this .age = age;
23: }
24:
25: public String getName() {
26: return name;
27: }
28:
29: public void setName(String name) {
30: this .name = name;
31: }
32:
33: public int hashCode() {
34: final int PRIME = 31;
35: int result = 1;
36: result = PRIME * result + age;
37: result = PRIME * result
38: + ((name == null) ? 0 : name.hashCode());
39: return result;
40: }
41:
42: public boolean equals(Object obj) {
43: if (this == obj)
44: return true;
45: if (obj == null)
46: return false;
47: if (getClass() != obj.getClass())
48: return false;
49: final PersonWithEquals other = (PersonWithEquals) obj;
50: if (age != other.age)
51: return false;
52: if (name == null) {
53: if (other.name != null)
54: return false;
55: } else if (!name.equals(other.name))
56: return false;
57: return true;
58: }
59:
60: }
|