Merge "Turn extension/pom.xml into an aggregator"
[openflowplugin.git] / openflowjava / openflow-protocol-api / src / main / java / org / opendaylight / openflowjava / protocol / api / keys / MessageCodeKey.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 package org.opendaylight.openflowjava.protocol.api.keys;
9
10 /**
11  * Key for a message code.
12  *
13  * @author michal.polkorab
14  */
15 public class MessageCodeKey {
16
17     private final short msgVersion;
18     private final int msgType;
19     private final Class<?> clazz;
20
21     /**
22      * Constructor.
23      *
24      * @param version wire protocol version
25      * @param value used as distinguisher (read from binary data / buffer)
26      * @param clazz class of object that is going to be deserialized
27      */
28     public MessageCodeKey(short version, int value, Class<?> clazz) {
29         this.msgVersion = version;
30         this.msgType = value;
31         this.clazz = clazz;
32     }
33
34     public int getMsgType() {
35         return this.msgType;
36     }
37
38     public Class<?> getClazz() {
39         return this.clazz;
40     }
41
42     @Override
43     public int hashCode() {
44         final int prime = 31;
45         int result = 1;
46         result = prime * result + (clazz == null ? 0 : clazz.hashCode());
47         result = prime * result + msgType;
48         result = prime * result + msgVersion;
49         return result;
50     }
51
52     @Override
53     public boolean equals(Object obj) {
54         if (this == obj) {
55             return true;
56         }
57         if (obj == null) {
58             return false;
59         }
60         if (!(obj instanceof MessageCodeKey)) {
61             return false;
62         }
63         MessageCodeKey other = (MessageCodeKey) obj;
64         if (clazz == null) {
65             if (other.clazz != null) {
66                 return false;
67             }
68         } else if (!clazz.equals(other.clazz)) {
69             return false;
70         }
71         if (msgType != other.msgType) {
72             return false;
73         }
74         if (msgVersion != other.msgVersion) {
75             return false;
76         }
77         return true;
78     }
79
80     @Override
81     public String toString() {
82         return "msgVersion: " + msgVersion + " objectClass: " + clazz.getName() + " msgType: " + msgType;
83     }
84 }