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