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