Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. package zti;
  2.  
  3. import java.security.Principal;
  4.  
  5. public class MyPrincipal implements Principal {
  6. private final String name;
  7.  
  8. public MyPrincipal(String name) {
  9. if(name == null) {
  10. throw new IllegalArgumentException("name cannot be null!");
  11. }
  12. this.name = name;
  13. }
  14.  
  15. public String getName() {
  16. return name;
  17. }
  18.  
  19. public String toString() {
  20. return "Principal with name: "+name;
  21. }
  22.  
  23. public boolean equals(Object obj) {
  24. if(obj == null) return false;
  25. if(obj == this) return true;
  26. if(!(obj instanceof MyPrincipal)) return false;
  27. MyPrincipal another = (MyPrincipal) obj;
  28. return name.equals(another.getName());
  29. }
  30.  
  31. public int hashCode() {
  32. return name.hashCode();
  33. }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement