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