-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathPerson.java
More file actions
36 lines (29 loc) · 890 Bytes
/
Person.java
File metadata and controls
36 lines (29 loc) · 890 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
// Doesn't creates unnecessary duplicate objects - page 21
package effectivejava.chapter2;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
class Person {
private final Date birthDate;
public Person(Date birthDate) {
// Defensive copy - see Item 39 ±£»¤ÐÔ¿½±´
this.birthDate = new Date(birthDate.getTime());
}
// Other fields, methods
/**
* The starting and ending dates of the baby boom.
*/
private static final Date BOOM_START;
private static final Date BOOM_END;
static {
Calendar gmtCal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
gmtCal.set(1946, Calendar.JANUARY, 1, 0, 0, 0);
BOOM_START = gmtCal.getTime();
gmtCal.set(1965, Calendar.JANUARY, 1, 0, 0, 0);
BOOM_END = gmtCal.getTime();
}
public boolean isBabyBoomer() {
return birthDate.compareTo(BOOM_START) >= 0
&& birthDate.compareTo(BOOM_END) < 0;
}
}