Fix broken hashCode & equals in FlowEntity related classes
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / matches / MatchVlanVid.java
1 /*
2  * Copyright © 2017 Red Hat, Inc. and others.
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.genius.mdsalutil.matches;
9
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatch;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
15
16 /**
17  * VLAN identifier match.
18  */
19 public class MatchVlanVid extends MatchInfoHelper<VlanMatch, VlanMatchBuilder> {
20
21     private final int vlanId;
22
23     public MatchVlanVid(int vlanId) {
24         this.vlanId = vlanId;
25     }
26
27     @Override
28     protected void applyValue(MatchBuilder matchBuilder, VlanMatch value) {
29         matchBuilder.setVlanMatch(value);
30     }
31
32     @Override
33     protected void populateBuilder(VlanMatchBuilder builder) {
34         builder.setVlanId(new VlanIdBuilder()
35                 .setVlanId(new VlanId(vlanId))
36                 .setVlanIdPresent(vlanId != 0)
37                 .build());
38     }
39
40     public int getVlanId() {
41         return vlanId;
42     }
43
44     @Override
45     public boolean equals(Object other) {
46         if (this == other) {
47             return true;
48         }
49         if (other == null || getClass() != other.getClass()) {
50             return false;
51         }
52         if (!super.equals(other)) {
53             return false;
54         }
55
56         MatchVlanVid that = (MatchVlanVid) other;
57
58         return vlanId == that.vlanId;
59     }
60
61     @Override
62     public int hashCode() {
63         int result = super.hashCode();
64         result = 31 * result + vlanId;
65         return result;
66     }
67
68     @Override
69     public String toString() {
70         return "MatchVlanVid[" + vlanId + "]";
71     }
72
73 }