SHARE
TWEET

Untitled

a guest Apr 24th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top