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