Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Employee {
- private int empNo;
- private String name;
- private Set<String> skills;
- public Employee(int empNo, String name, Set<String> skills) {
- this.empNo = empNo;
- this.name = name;
- this.skills = new HashSet<>(skills); // defensive copy
- }
- public int getEmpNo() {
- return empNo;
- }
- public String getName() {
- return name;
- }
- public Set<String> getSkills() {
- return new HashSet<>(skills); // return copy to maintain immutability
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (!(o instanceof Employee)) return false;
- Employee employee = (Employee) o;
- return empNo == employee.empNo &&
- Objects.equals(name, employee.name) &&
- Objects.equals(skills, employee.skills);
- }
- @Override
- public int hashCode() {
- return Objects.hash(empNo, name, skills);
- }
- @Override
- public String toString() {
- return "Employee{empNo=" + empNo + ", name='" + name + "', skills=" + skills + "}";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement