Fix broken hashCode & equals in FlowEntity related classes
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / matches / MatchArpTpa.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.genius.mdsalutil.NWUtil;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Prefix;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatch;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._3.match.ArpMatchBuilder;
15
16 /**
17  * ARP target transport address match.
18  */
19 public class MatchArpTpa extends MatchInfoHelper<ArpMatch, ArpMatchBuilder> {
20
21     private final Ipv4Prefix address;
22
23     public MatchArpTpa(Ipv4Prefix address) {
24         this.address = address;
25     }
26
27     public MatchArpTpa(long ip, long mask) {
28         this(new Ipv4Prefix(NWUtil.longToIpv4(ip, mask)));
29     }
30
31     public MatchArpTpa(String ip, String mask) {
32         this(new Ipv4Prefix(ip + "/" + mask));
33     }
34
35     @Override
36     protected void applyValue(MatchBuilder matchBuilder, ArpMatch value) {
37         matchBuilder.setLayer3Match(value);
38     }
39
40     @Override
41     protected void populateBuilder(ArpMatchBuilder builder) {
42         builder.setArpTargetTransportAddress(address);
43     }
44
45     public Ipv4Prefix getAddress() {
46         return address;
47     }
48
49     @Override
50     public boolean equals(Object other) {
51         if (this == other) {
52             return true;
53         }
54         if (other == null || getClass() != other.getClass()) {
55             return false;
56         }
57         if (!super.equals(other)) {
58             return false;
59         }
60
61         MatchArpTpa that = (MatchArpTpa) other;
62
63         return address != null ? address.equals(that.address) : that.address == null;
64     }
65
66     @Override
67     public int hashCode() {
68         int result = super.hashCode();
69         result = 31 * result + (address != null ? address.hashCode() : 0);
70         return result;
71     }
72
73     @Override
74     public String toString() {
75         return "MatchArpTpa[" + address + "]";
76     }
77
78 }