BUG-4283: experimenter msg support - deserialization part
[openflowjava.git] / openflow-protocol-api / src / main / java / org / opendaylight / openflowjava / protocol / api / keys / ExperimenterIdDeserializerKey.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.openflowjava.protocol.api.util.EncodeConstants;
12 import org.opendaylight.yangtools.yang.binding.DataContainer;
13
14 /**
15  * @author michal.polkorab
16  *
17  */
18 public class ExperimenterIdDeserializerKey extends MessageCodeKey
19         implements ExperimenterDeserializerKey {
20
21     private long experimenterId;
22
23     /**
24      * @param <E> type of target experimenter object
25      * @param version protocol wire version
26      * @param experimenterId experimenter / vendor ID
27      * @param objectClass class of created object
28      */
29     public <E extends DataContainer> ExperimenterIdDeserializerKey(short version,
30                                                                    long experimenterId, Class<E> objectClass) {
31         super(version, EncodeConstants.EXPERIMENTER_VALUE, objectClass);
32         this.experimenterId = experimenterId;
33     }
34
35     protected int hashCodeOfLong(long longValue) {
36         return (int) (longValue ^ (longValue >>> 32));
37     }
38
39     @Override
40     public int hashCode() {
41         final int prime = 31;
42         int result = super.hashCode();
43         result = prime * result + hashCodeOfLong(experimenterId);
44         return result;
45     }
46
47     @Override
48     public boolean equals(Object obj) {
49         if (this == obj) {
50             return true;
51         }
52         if (!super.equals(obj)) {
53             return false;
54         }
55         if (!(obj instanceof ExperimenterIdDeserializerKey)) {
56             return false;
57         }
58         ExperimenterIdDeserializerKey other = (ExperimenterIdDeserializerKey) obj;
59         if (experimenterId != other.experimenterId) {
60             return false;
61         }
62         return true;
63     }
64
65     @Override
66     public String toString() {
67         return super.toString() + " experimenterID: " + experimenterId;
68     }
69 }