Fix checkstyle violations in openflow-protocol-api
[openflowplugin.git] / openflowjava / openflow-protocol-api / src / main / java / org / opendaylight / openflowjava / protocol / api / keys / 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 package org.opendaylight.openflowjava.protocol.api.keys;
9
10 /**
11  * Class used as a key in {@link org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry}.
12  *
13  * @author michal.polkorab
14  * @author timotej.kubas
15  * @param <E> message type (class)
16  */
17 public class MessageTypeKey<E> {
18
19     private final Class<? extends E> msgType;
20     private final short msgVersion;
21
22     /**
23      * Constructor.
24      *
25      * @param msgVersion protocol version
26      * @param msgType type of message - class of serialized object
27      */
28     public MessageTypeKey(short msgVersion, Class<? extends E> msgType) {
29         this.msgType = msgType;
30         this.msgVersion = msgVersion;
31     }
32
33     @Override
34     public String toString() {
35         return "msgVersion: " + msgVersion + " objectType: " + 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.hashCode());
43         result = prime * result + msgVersion;
44         return result;
45     }
46
47     @Override
48     public boolean equals(Object obj) {
49         if (this == obj) {
50             return true;
51         }
52         if (obj == null) {
53             return false;
54         }
55         if (!(obj instanceof MessageTypeKey)) {
56             return false;
57         }
58         MessageTypeKey<?> other = (MessageTypeKey<?>) obj;
59         if (msgType == null) {
60             if (other.msgType != null) {
61                 return false;
62             }
63         } else if (!msgType.equals(other.msgType)) {
64             return false;
65         }
66         if (msgVersion != other.msgVersion) {
67             return false;
68         }
69         return true;
70     }
71 }