KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > pool > ConnectionKey


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

18 package org.apache.activemq.pool;
19
20 /**
21  * A cache key for the connection details
22  *
23  * @version $Revision: 1.1 $
24  */

25 public class ConnectionKey {
26     private String JavaDoc userName;
27     private String JavaDoc password;
28     private int hash;
29
30     public ConnectionKey(String JavaDoc password, String JavaDoc userName) {
31         this.password = password;
32         this.userName = userName;
33         hash = 31;
34         if (userName != null) {
35             hash += userName.hashCode();
36         }
37         hash *= 31;
38         if (password != null) {
39             hash += password.hashCode();
40         }
41     }
42
43     public int hashCode() {
44         return hash;
45     }
46
47     public boolean equals(Object JavaDoc that) {
48         if (this == that) {
49             return true;
50         }
51         if (that instanceof ConnectionKey) {
52             return equals((ConnectionKey) that);
53         }
54         return false;
55     }
56
57     public boolean equals(ConnectionKey that) {
58        return isEqual(this.userName, that.userName) && isEqual(this.password, that.password);
59     }
60
61     public String JavaDoc getPassword() {
62         return password;
63     }
64
65     public String JavaDoc getUserName() {
66         return userName;
67     }
68
69     public static boolean isEqual(Object JavaDoc o1, Object JavaDoc o2) {
70         if (o1 == o2) {
71             return true;
72         }
73         return (o1 != null && o2 != null && o1.equals(o2));
74     }
75
76
77 }
78
Popular Tags