Use ByteBuf.readRetainedSlice()
[openflowplugin.git] / openflowjava / openflow-protocol-api / src / main / java / org / opendaylight / openflowjava / protocol / api / keys / ExperimenterIdSerializerKey.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 package org.opendaylight.openflowjava.protocol.api.keys;
9
10 import static java.util.Objects.requireNonNull;
11
12 import org.opendaylight.yangtools.yang.binding.DataContainer;
13 import org.opendaylight.yangtools.yang.common.Uint32;
14 import org.opendaylight.yangtools.yang.common.Uint8;
15
16 /**
17  * Key for an experimenter id serializer.
18  *
19  * @author michal.polkorab
20  * @param <T> class of object to be serialized
21  */
22 public class ExperimenterIdSerializerKey<T extends DataContainer> extends MessageTypeKey<T>
23         implements ExperimenterSerializerKey {
24
25     private final Uint32 experimenterId;
26
27     /**
28      * Constructor.
29      *
30      * @param msgVersion protocol wire version
31      * @param experimenterId experimenter / vendor ID
32      * @param objectClass class of object to be serialized
33      */
34     public ExperimenterIdSerializerKey(final Uint8 msgVersion,
35                                        final Uint32 experimenterId, final Class<T> objectClass) {
36         super(msgVersion, objectClass);
37         this.experimenterId = requireNonNull(experimenterId);
38     }
39
40     @Override
41     public int hashCode() {
42         final int prime = 31;
43         int result = super.hashCode();
44         result = prime * result + experimenterId.hashCode();
45         return result;
46     }
47
48     protected int hashCodeOfLong(final long longValue) {
49         return (int) (longValue ^ longValue >>> 32);
50     }
51
52     @Override
53     public boolean equals(final Object obj) {
54         if (this == obj) {
55             return true;
56         }
57         if (!super.equals(obj)) {
58             return false;
59         }
60         if (!(obj instanceof ExperimenterIdSerializerKey)) {
61             return false;
62         }
63         ExperimenterIdSerializerKey<?> other = (ExperimenterIdSerializerKey<?>) obj;
64         if (experimenterId != other.experimenterId) {
65             return false;
66         }
67         return true;
68     }
69
70     @Override
71     public String toString() {
72         return super.toString() + " experimenterID: " + experimenterId;
73     }
74 }