KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > util > SubscriptionKey


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.util;
19
20 import org.apache.activemq.command.SubscriptionInfo;
21
22 public class SubscriptionKey {
23     
24     public final String JavaDoc clientId;
25     public final String JavaDoc subscriptionName;
26     private final int hashValue;
27
28
29     public SubscriptionKey(SubscriptionInfo info) {
30         this(info.getClientId(), info.getSubcriptionName());
31     }
32
33     public SubscriptionKey(String JavaDoc clientId, String JavaDoc subscriptionName) {
34         this.clientId = clientId;
35         this.subscriptionName = subscriptionName != null? subscriptionName : "NOT_SET";
36         hashValue = clientId.hashCode()^this.subscriptionName.hashCode();
37     }
38
39
40     public int hashCode() {
41         return hashValue;
42     }
43     
44     public boolean equals(Object JavaDoc o) {
45         try {
46             SubscriptionKey key = (SubscriptionKey) o;
47             return key.clientId.equals(clientId) && key.subscriptionName.equals(subscriptionName);
48         } catch (Throwable JavaDoc e) {
49             return false;
50         }
51     }
52     
53     public String JavaDoc toString() {
54         return clientId+":"+subscriptionName;
55     }
56
57     public String JavaDoc getClientId() {
58         return clientId;
59     }
60
61     public String JavaDoc getSubscriptionName() {
62         return subscriptionName;
63     }
64 }
65
Popular Tags