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