Bug 2756 - Match model update
[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 objectType class of serialized object
30      * @param oxmClass oxm_class (see specification)
31      * @param oxmField oxm_field (see specification)
32      */
33     public MatchEntrySerializerKey(short msgVersion, Class<C> oxmClass,
34             Class<F> oxmField) {
35         super(msgVersion, MatchEntry.class);
36         this.oxmClass = oxmClass;
37         this.oxmField = oxmField;
38     }
39
40     /**
41      * @param experimenterId experimenter / vendor ID
42      */
43     public void setExperimenterId(Long experimenterId) {
44         this.experimenterId = experimenterId;
45     }
46
47     @Override
48     public int hashCode() {
49         final int prime = 31;
50         int result = super.hashCode();
51         result = prime * result + ((experimenterId == null) ? 0 : experimenterId.hashCode());
52         result = prime * result + ((oxmClass == null) ? 0 : oxmClass.hashCode());
53         result = prime * result + ((oxmField == null) ? 0 : oxmField.hashCode());
54         return result;
55     }
56
57     @Override
58     public boolean equals(Object obj) {
59         if (this == obj) {
60             return true;
61         }
62         if (!super.equals(obj)) {
63             return false;
64         }
65         if (getClass() != obj.getClass()) {
66             return false;
67         }
68         MatchEntrySerializerKey<?, ?> other = (MatchEntrySerializerKey<?, ?>) obj;
69         if (experimenterId == null) {
70             if (other.experimenterId != null) {
71                 return false;
72             }
73         } else if (!experimenterId.equals(other.experimenterId)) {
74             return false;
75         }
76         if (oxmClass == null) {
77             if (other.oxmClass != null) {
78                 return false;
79             }
80         } else if (!oxmClass.equals(other.oxmClass)) {
81             return false;
82         }
83         if (oxmField == null) {
84             if (other.oxmField != null) {
85                 return false;
86             }
87         } else if (!oxmField.equals(other.oxmField)) {
88             return false;
89         }
90         return true;
91     }
92
93     @Override
94     public String toString() {
95         return super.toString() + " oxm_class: " + oxmClass.getName() + " oxm_field: "
96                 + oxmField.getName() + " experimenterID: " + experimenterId;
97     }
98 }