7885b7e17dadf5fcd16409f67314e4d0104b34fc
[openflowjava.git] / openflow-protocol-api / src / main / java / org / opendaylight / openflowjava / protocol / api / extensibility / MessageTypeKey.java
1 /*
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.api.extensibility;
10
11
12 /**
13  * Class used as a key in {@link SerializerRegistry}
14  * @author michal.polkorab
15  * @author timotej.kubas
16  * @param <E> message type (class)
17  */
18 public class MessageTypeKey<E> {
19
20     private final Class<E> msgType;
21     private final short msgVersion;
22     
23     /**
24      * @param msgVersion protocol version
25      * @param msgType type of message
26      */
27     public MessageTypeKey(short msgVersion, Class<E> msgType) {
28         super();
29         this.msgType = msgType;
30         this.msgVersion = msgVersion;
31     }
32     
33     @Override
34     public String toString() {
35         return "msgVersion: " + msgVersion + " msgType: " + msgType.getName();
36     }
37
38     @Override
39     public int hashCode() {
40         final int prime = 31;
41         int result = 1;
42         result = prime * result + ((msgType == null) ? 0 : msgType.getName().hashCode());
43         return result;
44     }
45
46     @Override
47     public boolean equals(Object obj) {
48         if (this == obj)
49             return true;
50         if (obj == null)
51             return false;
52         if (getClass() != obj.getClass())
53             return false;
54         MessageTypeKey<?> other = (MessageTypeKey<?>) obj;
55         if (msgType == null) {
56             if (other.msgType != null)
57                 return false;
58         } else if (!other.msgType.getName().equals(msgType.getName()))
59             return false;
60         if (msgVersion != other.msgVersion)
61             return false;
62         return true;
63     }
64  
65 }