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. package org.apache.commons.dbcp.datasources;
  17. import java.io.Serializable;
  18. /**
  19. * Holds a username, password pair.
  20. * @version $Revision: 1.5 $ $Date: 2004/02/28 12:18:17 $
  21. */
  22. class UserPassKey implements Serializable {
  23. private String password;
  24. private String username;
  25. UserPassKey(String username, String password) {
  26. this.username = username;
  27. this.password = password;
  28. }
  29. /**
  30. * Get the value of password.
  31. * @return value of password.
  32. */
  33. public String getPassword() {
  34. return password;
  35. }
  36. /**
  37. * Get the value of username.
  38. * @return value of username.
  39. */
  40. public String getUsername() {
  41. return username;
  42. }
  43. /**
  44. * @return <code>true</code> if the username and password fields for both
  45. * objects are equal.
  46. * @see java.lang.Object#equals(java.lang.Object)
  47. */
  48. public boolean equals(Object obj) {
  49. if (obj == null) {
  50. return false;
  51. }
  52. if (obj == this) {
  53. return true;
  54. }
  55. if (!(obj instanceof UserPassKey)) {
  56. return false;
  57. }
  58. UserPassKey key = (UserPassKey) obj;
  59. boolean usersEqual =
  60. (this.username == null
  61. ? key.username == null
  62. : this.username.equals(key.username));
  63. boolean passwordsEqual =
  64. (this.password == null
  65. ? key.password == null
  66. : this.password.equals(key.password));
  67. return (usersEqual && passwordsEqual);
  68. }
  69. public int hashCode() {
  70. return (this.username != null ? this.username.hashCode() : 0);
  71. }
  72. public String toString() {
  73. StringBuffer sb = new StringBuffer(50);
  74. sb.append("UserPassKey(");
  75. sb.append(username).append(", ").append(password).append(')');
  76. return sb.toString();
  77. }
  78. }