Coverage Report - org.apache.commons.messenger.ListenerKey
 
Classes in this File Line Coverage Branch Coverage Complexity
ListenerKey
0%
0/24
0%
0/20
3.4
 
 1  
 /*
 2  
  * Copyright (C) The Apache Software Foundation. All rights reserved.
 3  
  *
 4  
  * This software is published under the terms of the Apache Software License
 5  
  * version 1.1, a copy of which has been included with this distribution in
 6  
  * the LICENSE file.
 7  
  * 
 8  
  * $Id: ListenerKey.java 155459 2005-02-26 13:24:44Z dirkv $
 9  
  */
 10  
 package org.apache.commons.messenger;
 11  
 
 12  
 import javax.jms.Destination;
 13  
 import javax.jms.MessageListener;
 14  
 
 15  
 
 16  
 /** <p><code>ListenerKey</code> is an implementation class allowing a Destination, 
 17  
   * MessageListener and an optional selector to be used as a key to a Map so that 
 18  
   * a single subscription can be easily associated with a MessageConsumer.
 19  
   *
 20  
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
 21  
   * @version $Revision: 155459 $
 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  0
         this( destination, messageListener, null );
 32  0
     }
 33  
     
 34  0
     public ListenerKey(Destination destination, MessageListener messageListener, String selector) {
 35  0
         this.destination = destination;
 36  0
         this.messageListener = messageListener;
 37  0
         this.selector = selector;
 38  0
         this.hashCode = destination.hashCode() ^ messageListener.hashCode();
 39  0
         if ( selector != null ) {
 40  0
             this.hashCode ^= selector.hashCode();
 41  
         }
 42  0
     }
 43  
     
 44  
     public int hashCode() {
 45  0
         return hashCode;
 46  
     }
 47  
     
 48  
     public boolean equals(Object that) {
 49  0
         if ( this == that ) {
 50  0
             return true;
 51  
         }
 52  0
         if (that instanceof ListenerKey) {
 53  0
             return equals((ListenerKey) that);
 54  
         }
 55  0
         return false;
 56  
     }
 57  
     
 58  
     public boolean equals(ListenerKey that) {
 59  0
         if ( this == that ) {
 60  0
             return true;
 61  
         }
 62  0
         if ( this.hashCode == that.hashCode ) {
 63  0
             if ( this.destination.equals( that.destination ) && this.messageListener.equals( that.messageListener) ) {
 64  0
                 if ( this.selector == that.selector ) {
 65  0
                     return true;
 66  
                 }
 67  0
                 return this.selector != null && this.selector.equals( that.selector );
 68  
             }
 69  
         }
 70  0
         return false;
 71  
     }
 72  
         
 73  
 }
 74