-
-
Notifications
You must be signed in to change notification settings - Fork 756
Expand file tree
/
Copy pathEmployee.java
More file actions
40 lines (33 loc) · 1.04 KB
/
Employee.java
File metadata and controls
40 lines (33 loc) · 1.04 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
import java.util.Objects;
import java.util.Optional;
class Employee {
private final int id;
private final String name;
private final String department;
public Employee(int id, String name, String department) {
this.id = id;
this.name = name;
this.department = department;
}
public Optional<Integer> getNullableId() {
return Optional.ofNullable(id);
}
public Optional<String> getNullableName() {
return Optional.ofNullable(name);
}
public Optional<String> getNullableDepartment() {
return Optional.ofNullable(department);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Employee employee = (Employee) o;
return id == employee.id &&
Objects.equals(name, employee.name) && Objects.equals(department, employee.department);
}
@Override
public int hashCode() {
return Objects.hash(id, name, department);
}
}