d2ce5a91e8f8b49d02ef5811642900ea3863f304
[openflowjava.git] / openflow-protocol-api / src / main / java / org / opendaylight / openflowjava / protocol / api / extensibility / EnhancedMessageTypeKey.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 /**\r
12  * More specific key for {@link SerializerRegistry}\r
13  * @author michal.polkorab\r
14  * @param <E> main type\r
15  * @param <F> specific type\r
16  */\r
17 public class EnhancedMessageTypeKey<E, F> extends MessageTypeKey<E> {\r
18 \r
19     private final Class<F> msgType2;\r
20 \r
21     /**\r
22      * @param msgVersion\r
23      * @param msgType\r
24      * @param msgType2\r
25      */\r
26     public EnhancedMessageTypeKey(short msgVersion, Class<E> msgType, Class<F> msgType2) {\r
27         super(msgVersion, msgType);\r
28         this.msgType2 = msgType2;\r
29     }\r
30 \r
31     @Override\r
32     public int hashCode() {\r
33         final int prime = 31;\r
34         int result = super.hashCode();\r
35         result = prime * result + ((msgType2 == null) ? 0 : msgType2.hashCode());\r
36         return result;\r
37     }\r
38     \r
39     @Override\r
40     public boolean equals(Object obj) {\r
41         if (this == obj) {\r
42             return true;\r
43         }\r
44         if (!super.equals(obj)) {\r
45             return false;\r
46         }\r
47         if (getClass() != obj.getClass()) {\r
48             return false;\r
49         }\r
50         @SuppressWarnings("rawtypes")\r
51         EnhancedMessageTypeKey other = (EnhancedMessageTypeKey) obj;\r
52         if (msgType2 == null) {\r
53             if (other.msgType2 != null) {\r
54                 return false;\r
55             }\r
56         } else if (!msgType2.getName().equals(other.msgType2.getName())) {\r
57             return false;\r
58         }\r
59         return true;\r
60     }\r
61 \r
62     @Override\r
63     public String toString() {\r
64         return super.toString() + " msgType2: " + msgType2.getName();\r
65     }\r
66 }