changes for config subsystem - BUG 754
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / serialization / 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.impl.serialization;
10
11 import org.opendaylight.yangtools.yang.binding.DataObject;
12
13 /**
14  * Class used as a key in {@link EncoderTable}
15  * @author michal.polkorab
16  * @author timotej.kubas
17  * @param <E> message type (class)
18  */
19 public class MessageTypeKey<E extends DataObject> {
20
21     private final Class<E> msgType;
22     private final short msgVersion;
23     
24     /**
25      * @param msgVersion protocol version
26      * @param msgType type of message
27      */
28     public MessageTypeKey(short msgVersion, Class<E> msgType) {
29         super();
30         this.msgType = msgType;
31         this.msgVersion = msgVersion;
32     }
33     
34     /**
35      * @return msgVersion
36      */
37     public short getMsgVersion() {
38         return msgVersion;
39     }
40
41     /**
42      * @return the msgType
43      */
44     public Class<E> getMsgType() {
45         return msgType;
46     }
47
48     @Override
49     public String toString() {
50         return "msgVersion: " + msgVersion + " msgType: " + msgType.getName();
51     }
52
53     @Override
54     public int hashCode() {
55         final int prime = 31;
56         int result = 1;
57         result = prime * result + msgVersion;
58         return result;
59     }
60
61     @Override
62     public boolean equals(Object obj) {
63         if (this == obj)
64             return true;
65         if (obj == null)
66             return false;
67         if (getClass() != obj.getClass())
68             return false;
69         MessageTypeKey<?> other = (MessageTypeKey<?>) obj;
70         if (msgType == null) {
71             if (other.msgType != null)
72                 return false;
73         } else if (!other.msgType.isAssignableFrom(msgType))
74             return false;
75         if (msgVersion != other.msgVersion)
76             return false;
77         return true;
78     }
79  
80 }