001 /** 002 * 003 * Copyright 2005 Protique Ltd 004 * 005 * Licensed under the Apache License, Version 2.0 (the "License"); 006 * you may not use this file except in compliance with the License. 007 * You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 * 017 **/ 018 package org.activemq.pool; 019 020 /** 021 * A cache key for the connection details 022 * 023 * @version $Revision: 1.1 $ 024 */ 025 public class ConnectionKey { 026 private String userName; 027 private String password; 028 private int hash; 029 030 public ConnectionKey(String password, String userName) { 031 this.password = password; 032 this.userName = userName; 033 hash = 31; 034 if (userName != null) { 035 hash += userName.hashCode(); 036 } 037 hash *= 31; 038 if (password != null) { 039 hash += password.hashCode(); 040 } 041 } 042 043 public int hashCode() { 044 return hash; 045 } 046 047 public boolean equals(Object that) { 048 if (this == that) { 049 return true; 050 } 051 if (that instanceof ConnectionKey) { 052 return equals((ConnectionKey) that); 053 } 054 return false; 055 } 056 057 public boolean equals(ConnectionKey that) { 058 return isEqual(this.userName, that.userName) && isEqual(this.password, that.password); 059 } 060 061 public String getPassword() { 062 return password; 063 } 064 065 public String getUserName() { 066 return userName; 067 } 068 069 public static boolean isEqual(Object o1, Object o2) { 070 if (o1 == o2) { 071 return true; 072 } 073 return (o1 != null && o2 != null && o1.equals(o2)); 074 } 075 076 077 }