01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: package org.apache.commons.dbcp.datasources;
19:
20: import java.io.Serializable;
21:
22: /**
23: * Holds a username, password pair.
24: * @version $Revision: 479137 $ $Date: 2006-11-25 08:51:48 -0700 (Sat, 25 Nov 2006) $
25: */
26: class UserPassKey implements Serializable {
27: private String password;
28: private String username;
29:
30: UserPassKey(String username, String password) {
31: this .username = username;
32: this .password = password;
33: }
34:
35: /**
36: * Get the value of password.
37: * @return value of password.
38: */
39: public String getPassword() {
40: return password;
41: }
42:
43: /**
44: * Get the value of username.
45: * @return value of username.
46: */
47: public String getUsername() {
48: return username;
49: }
50:
51: /**
52: * @return <code>true</code> if the username and password fields for both
53: * objects are equal.
54: * @see java.lang.Object#equals(java.lang.Object)
55: */
56: public boolean equals(Object obj) {
57: if (obj == null) {
58: return false;
59: }
60:
61: if (obj == this ) {
62: return true;
63: }
64:
65: if (!(obj instanceof UserPassKey)) {
66: return false;
67: }
68:
69: UserPassKey key = (UserPassKey) obj;
70:
71: boolean usersEqual = (this .username == null ? key.username == null
72: : this .username.equals(key.username));
73:
74: boolean passwordsEqual = (this .password == null ? key.password == null
75: : this .password.equals(key.password));
76:
77: return (usersEqual && passwordsEqual);
78: }
79:
80: public int hashCode() {
81: return (this .username != null ? this .username.hashCode() : 0);
82: }
83:
84: public String toString() {
85: StringBuffer sb = new StringBuffer(50);
86: sb.append("UserPassKey(");
87: sb.append(username).append(", ").append(password).append(')');
88: return sb.toString();
89: }
90: }
|