Extensibility support (serialization part)
[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     /**
34      * @return msgVersion
35      */
36     public short getMsgVersion() {
37         return msgVersion;
38     }
39
40     /**
41      * @return the msgType
42      */
43     public Class<E> getMsgType() {
44         return msgType;
45     }
46
47     @Override
48     public String toString() {
49         return "msgVersion: " + msgVersion + " msgType: " + msgType.getName();
50     }
51
52     @Override
53     public int hashCode() {
54         final int prime = 31;
55         int result = 1;
56         result = prime * result + msgVersion;
57         return result;
58     }
59
60     @Override
61     public boolean equals(Object obj) {
62         if (this == obj)
63             return true;
64         if (obj == null)
65             return false;
66         if (getClass() != obj.getClass())
67             return false;
68         MessageTypeKey<?> other = (MessageTypeKey<?>) obj;
69         if (msgType == null) {
70             if (other.msgType != null)
71                 return false;
72         } else if (!other.msgType.isAssignableFrom(msgType))
73             return false;
74         if (msgVersion != other.msgVersion)
75             return false;
76         return true;
77     }
78  
79 }