KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > base > SimplePrincipal


1 /*
2  * Created on Feb 13, 2005
3  */

4 package com.nightlabs.ipanema.base;
5
6 import java.security.Principal JavaDoc;
7
8 /**
9  * @author Marco Schulze - marco at nightlabs dot de
10  */

11 public class SimplePrincipal implements Principal JavaDoc, java.io.Serializable JavaDoc
12 {
13     private String JavaDoc name;
14
15     public SimplePrincipal(String JavaDoc name)
16     {
17         this.name = name;
18     }
19
20     /**
21      * @other The object with which to compare
22      * @return true if other implements Principal and name equals other.getName();
23      */

24     public boolean equals(Object JavaDoc other)
25     {
26         if (other == this)
27             return true;
28
29         if (!(other instanceof Principal JavaDoc))
30             return false;
31
32         String JavaDoc otherName = ((Principal JavaDoc)other).getName();
33
34         if (name == null)
35             return otherName == null;
36      
37         return name.equals(otherName);
38     }
39
40     public int hashCode()
41     {
42         return (name == null ? 0 : name.hashCode());
43     }
44
45     public String JavaDoc toString()
46     {
47         return name;
48     }
49
50     public String JavaDoc getName()
51     {
52         return name;
53     }
54 }
Popular Tags