Advertisement
thewitchking

Untitled

May 30th, 2025
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.12 KB | None | 0 0
  1. class Employee {
  2.     private int empNo;
  3.     private String name;
  4.     private Set<String> skills;
  5.  
  6.     public Employee(int empNo, String name, Set<String> skills) {
  7.         this.empNo = empNo;
  8.         this.name = name;
  9.         this.skills = new HashSet<>(skills); // defensive copy
  10.     }
  11.  
  12.     public int getEmpNo() {
  13.         return empNo;
  14.     }
  15.  
  16.     public String getName() {
  17.         return name;
  18.     }
  19.  
  20.     public Set<String> getSkills() {
  21.         return new HashSet<>(skills); // return copy to maintain immutability
  22.     }
  23.  
  24.     @Override
  25.     public boolean equals(Object o) {
  26.         if (this == o) return true;
  27.         if (!(o instanceof Employee)) return false;
  28.         Employee employee = (Employee) o;
  29.         return empNo == employee.empNo &&
  30.                Objects.equals(name, employee.name) &&
  31.                Objects.equals(skills, employee.skills);
  32.     }
  33.  
  34.     @Override
  35.     public int hashCode() {
  36.         return Objects.hash(empNo, name, skills);
  37.     }
  38.  
  39.     @Override
  40.     public String toString() {
  41.         return "Employee{empNo=" + empNo + ", name='" + name + "', skills=" + skills + "}";
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement