7759c0bf0b64e1431b0ffbefabc44d1928b9809f
[openflowjava.git] / openflow-protocol-api / src / main / java / org / opendaylight / openflowjava / protocol / api / keys / InstructionSerializerKey.java
1 /*\r
2  * Copyright (c) 2014 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 \r
9 package org.opendaylight.openflowjava.protocol.api.keys;\r
10 \r
11 import org.opendaylight.openflowjava.protocol.api.extensibility.MessageTypeKey;\r
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.InstructionBase;\r
14 \r
15 /**\r
16  * @author michal.polkorab\r
17  * @param <TYPE> action type\r
18  */\r
19 public class InstructionSerializerKey<TYPE extends InstructionBase>\r
20         extends MessageTypeKey<Instruction>{\r
21 \r
22     private Class<TYPE> instructionType;\r
23     private Long experimenterId;\r
24 \r
25     /**\r
26      * @param msgVersion protocol wire version\r
27      * @param objectType class of serialized object (Instruction.class)\r
28      * @param instructionType type of instruction\r
29      * @param experimenterId experimenter / vendor ID\r
30      */\r
31     public InstructionSerializerKey(short msgVersion, Class<TYPE> instructionType,\r
32             Long experimenterId) {\r
33         super(msgVersion, Instruction.class);\r
34         this.instructionType = instructionType;\r
35         this.experimenterId = experimenterId;\r
36     }\r
37 \r
38     @Override\r
39     public int hashCode() {\r
40         final int prime = 31;\r
41         int result = super.hashCode();\r
42         result = prime * result + ((experimenterId == null) ? 0 : experimenterId.hashCode());\r
43         result = prime * result + ((instructionType == null) ? 0 : instructionType.hashCode());\r
44         return result;\r
45     }\r
46 \r
47     @Override\r
48     public boolean equals(Object obj) {\r
49         if (this == obj) {\r
50             return true;\r
51         }\r
52         if (!super.equals(obj)) {\r
53             return false;\r
54         }\r
55         if (!(obj instanceof InstructionSerializerKey)) {\r
56             return false;\r
57         }\r
58         InstructionSerializerKey<?> other = (InstructionSerializerKey<?>) obj;\r
59         if (experimenterId == null) {\r
60             if (other.experimenterId != null) {\r
61                 return false;\r
62             }\r
63         } else if (!experimenterId.equals(other.experimenterId)) {\r
64             return false;\r
65         }\r
66         if (instructionType == null) {\r
67             if (other.instructionType != null) {\r
68                 return false;\r
69             }\r
70         } else if (!instructionType.equals(other.instructionType)) {\r
71             return false;\r
72         }\r
73         return true;\r
74     }\r
75 \r
76     @Override\r
77     public String toString() {\r
78         return super.toString() + " instructionType type: " + instructionType.getName()\r
79                 + " vendorID: " + experimenterId;\r
80     }\r
81 }