75fcd3e60045b4b2c901155d6501e8b886985c40
[openflowjava.git] / openflow-protocol-api / src / main / java / org / opendaylight / openflowjava / protocol / api / keys / MatchEntrySerializerKey.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.oxm.rev150225.MatchField;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OxmClassBase;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.match.entries.grouping.MatchEntry;
14
15 /**
16  * @author michal.polkorab
17  * @param <C> oxm_class (see specification)
18  * @param <F> oxm_field (see specification)
19  */
20 public final class MatchEntrySerializerKey<C extends OxmClassBase, F extends MatchField>
21         extends MessageTypeKey<MatchEntry> implements ExperimenterSerializerKey {
22
23     private Class<C> oxmClass;
24     private Class<F> oxmField;
25     private Long experimenterId;
26
27     /**
28      * @param msgVersion protocol wire version
29      * @param oxmClass oxm_class (see specification)
30      * @param oxmField oxm_field (see specification)
31      */
32     public MatchEntrySerializerKey(short msgVersion, Class<C> oxmClass,
33             Class<F> oxmField) {
34         super(msgVersion, MatchEntry.class);
35         this.oxmClass = oxmClass;
36         this.oxmField = oxmField;
37     }
38
39     /**
40      * @param experimenterId experimenter / vendor ID
41      */
42     public void setExperimenterId(Long experimenterId) {
43         this.experimenterId = experimenterId;
44     }
45
46     @Override
47     public int hashCode() {
48         final int prime = 31;
49         int result = super.hashCode();
50         result = prime * result + ((experimenterId == null) ? 0 : experimenterId.hashCode());
51         result = prime * result + ((oxmClass == null) ? 0 : oxmClass.hashCode());
52         result = prime * result + ((oxmField == null) ? 0 : oxmField.hashCode());
53         return result;
54     }
55
56     @Override
57     public boolean equals(Object obj) {
58         if (this == obj) {
59             return true;
60         }
61         if (!super.equals(obj)) {
62             return false;
63         }
64         if (getClass() != obj.getClass()) {
65             return false;
66         }
67         MatchEntrySerializerKey<?, ?> other = (MatchEntrySerializerKey<?, ?>) obj;
68         if (experimenterId == null) {
69             if (other.experimenterId != null) {
70                 return false;
71             }
72         } else if (!experimenterId.equals(other.experimenterId)) {
73             return false;
74         }
75         if (oxmClass == null) {
76             if (other.oxmClass != null) {
77                 return false;
78             }
79         } else if (!oxmClass.equals(other.oxmClass)) {
80             return false;
81         }
82         if (oxmField == null) {
83             if (other.oxmField != null) {
84                 return false;
85             }
86         } else if (!oxmField.equals(other.oxmField)) {
87             return false;
88         }
89         return true;
90     }
91
92     @Override
93     public String toString() {
94         return super.toString() + " oxm_class: " + oxmClass.getName() + " oxm_field: "
95                 + oxmField.getName() + " experimenterID: " + experimenterId;
96     }
97 }