KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > dbcp > datasources > UserPassKey


1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.commons.dbcp.datasources;
18
19 import java.io.Serializable JavaDoc;
20
21 /**
22  * Holds a username, password pair.
23  * @version $Revision: 1.5 $ $Date: 2004/02/28 12:18:17 $
24  */

25 class UserPassKey implements Serializable JavaDoc {
26     private String JavaDoc password;
27     private String JavaDoc username;
28     
29     UserPassKey(String JavaDoc username, String JavaDoc password) {
30         this.username = username;
31         this.password = password;
32     }
33         
34     /**
35      * Get the value of password.
36      * @return value of password.
37      */

38     public String JavaDoc getPassword() {
39         return password;
40     }
41     
42     /**
43      * Get the value of username.
44      * @return value of username.
45      */

46     public String JavaDoc getUsername() {
47         return username;
48     }
49     
50     /**
51      * @return <code>true</code> if the username and password fields for both
52      * objects are equal.
53      * @see java.lang.Object#equals(java.lang.Object)
54      */

55     public boolean equals(Object JavaDoc obj) {
56         if (obj == null) {
57             return false;
58         }
59
60         if (obj == this) {
61             return true;
62         }
63         
64         if (!(obj instanceof UserPassKey)) {
65             return false;
66         }
67         
68         UserPassKey key = (UserPassKey) obj;
69         
70         boolean usersEqual =
71             (this.username == null
72                 ? key.username == null
73                 : this.username.equals(key.username));
74                 
75         boolean passwordsEqual =
76             (this.password == null
77                 ? key.password == null
78                 : this.password.equals(key.password));
79
80         return (usersEqual && passwordsEqual);
81     }
82
83     public int hashCode() {
84         return (this.username != null ? this.username.hashCode() : 0);
85     }
86
87     public String JavaDoc toString() {
88         StringBuffer JavaDoc sb = new StringBuffer JavaDoc(50);
89         sb.append("UserPassKey(");
90         sb.append(username).append(", ").append(password).append(')');
91         return sb.toString();
92     }
93 }
94
Popular Tags