1
2
3
4
5
6
7
8
9
10 package org.apache.commons.messenger;
11
12 import javax.jms.Destination;
13 import javax.jms.MessageListener;
14
15
16
17
18
19
20
21
22
23 class ListenerKey {
24
25 private Destination destination;
26 private MessageListener messageListener;
27 private String selector;
28 private int hashCode;
29
30 public ListenerKey(Destination destination, MessageListener messageListener) {
31 this( destination, messageListener, null );
32 }
33
34 public ListenerKey(Destination destination, MessageListener messageListener, String selector) {
35 this.destination = destination;
36 this.messageListener = messageListener;
37 this.selector = selector;
38 this.hashCode = destination.hashCode() ^ messageListener.hashCode();
39 if ( selector != null ) {
40 this.hashCode ^= selector.hashCode();
41 }
42 }
43
44 public int hashCode() {
45 return hashCode;
46 }
47
48 public boolean equals(Object that) {
49 if ( this == that ) {
50 return true;
51 }
52 if (that instanceof ListenerKey) {
53 return equals((ListenerKey) that);
54 }
55 return false;
56 }
57
58 public boolean equals(ListenerKey that) {
59 if ( this == that ) {
60 return true;
61 }
62 if ( this.hashCode == that.hashCode ) {
63 if ( this.destination.equals( that.destination ) && this.messageListener.equals( that.messageListener) ) {
64 if ( this.selector == that.selector ) {
65 return true;
66 }
67 return this.selector != null && this.selector.equals( that.selector );
68 }
69 }
70 return false;
71 }
72
73 }
74