-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPerson.java
More file actions
159 lines (129 loc) · 2.88 KB
/
Person.java
File metadata and controls
159 lines (129 loc) · 2.88 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package cn.ccsu.beans;
import java.io.Serializable;
public class Person implements Comparable<Person>, Cloneable,Serializable {
/**
*
*/
private static final long serialVersionUID = 6398447481726571267L;
private String name;
private Integer age;
private String sex;
private Integer id;
private static short num = 0;
public Person() {
System.out.println("Person 类的无参构造方法");
}
@Override
public Object clone() {
Object obj = null;
try {
obj = super.clone();
} catch (CloneNotSupportedException e) {
e.printStackTrace();
}
return obj;
}
@Override
public String toString() {
return "Person [name=" + name + ", age=" + age + ", sex=" + sex + ", ID=" + id + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
result = prime * result + ((age == null) ? 0 : age.hashCode());
result = prime * result + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((sex == null) ? 0 : sex.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Person other = (Person) obj;
if (id == null) {
if (other.id != null)
return false;
} else if (!id.equals(other.id))
return false;
if (age == null) {
if (other.age != null)
return false;
} else if (!age.equals(other.age))
return false;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
if (sex == null) {
if (other.sex != null)
return false;
} else if (!sex.equals(other.sex))
return false;
return true;
}
public Person(String name, Integer age, String sex, Integer id) {
super();
this.name = name;
this.age = age;
this.sex = sex;
this.id = id;
System.out.println("带有4个参数的构造器");
}
public Person(String name, Integer age) {
super();
this.name = name;
this.age = age;
System.out.println("带有2个参数的构造器:"+(++Person.num));
}
@Override
public int compareTo(Person o) {
// TODO Auto-generated method stub
int i = this.id.compareTo(o.id);
if (i == 0) {
i = this.age.compareTo(o.age);
if (i == 0) {
i = this.name.compareTo(o.name);
if (i == 0) {
return this.sex.compareTo(o.sex);
} else {
return i;
}
} else {
return i;
}
} else {
return i;
}
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}