Repository navigation
Expand file tree
/
Copy pathPerson.java
More file actions
84 lines (67 loc) · 2.23 KB
/
Copy pathPerson.java
File metadata and controls
84 lines (67 loc) · 2.23 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
package de.codecentric.java8examples;
import java.time.LocalDate;
import java.time.Period;
/**
* A simple class that represents a person
*/
public class Person {
public enum Gender {
MALE, FEMALE
}
private final String firstName;
private final String lastName;
private final LocalDate birthDay;
private Gender gender;
public Person(String firstname, String lastName, LocalDate birthDay, Gender gender) {
this.firstName = firstname;
this.lastName = lastName;
this.birthDay = birthDay;
this.gender = gender;
}
public String getFirstName() {
return firstName;
}
public String getLastName() {
return lastName;
}
public LocalDate getBirthDay() {
return birthDay;
}
public Gender getGender() {
return gender;
}
public void setGender(Gender gender) {
this.gender = gender;
}
public int getAge() {
return Period.between(getBirthDay(), LocalDate.now()).getYears();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Person person = (Person) o;
if (birthDay != null ? !birthDay.equals(person.birthDay) : person.birthDay != null) return false;
if (gender != person.gender) return false;
if (lastName != null ? !lastName.equals(person.lastName) : person.lastName != null) return false;
if (firstName != null ? !firstName.equals(person.firstName) : person.firstName != null) return false;
return true;
}
@Override
public int hashCode() {
int result = firstName != null ? firstName.hashCode() : 0;
result = 31 * result + (lastName != null ? lastName.hashCode() : 0);
result = 31 * result + (birthDay != null ? birthDay.hashCode() : 0);
result = 31 * result + (gender != null ? gender.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Person{" +
"firstName='" + firstName + '\'' +
", lastName='" + lastName + '\'' +
", birthDay=" + birthDay +
", gender=" + gender +
'}';
}
}