Fix broken hashCode & equals in FlowEntity related classes
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / matches / MatchTcpDestinationPort.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.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatch;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.TcpMatchBuilder;
14
15 /**
16  * TCP destination port match.
17  */
18 public class MatchTcpDestinationPort extends MatchInfoHelper<TcpMatch, TcpMatchBuilder> {
19
20     private final int port;
21
22     public MatchTcpDestinationPort(int port) {
23         this.port = port;
24     }
25
26     @Override
27     protected void applyValue(MatchBuilder matchBuilder, TcpMatch value) {
28         matchBuilder.setLayer4Match(value);
29     }
30
31     @Override
32     protected void populateBuilder(TcpMatchBuilder builder) {
33         builder.setTcpDestinationPort(new PortNumber(port));
34     }
35
36     public int getPort() {
37         return port;
38     }
39
40     @Override
41     public boolean equals(Object other) {
42         if (this == other) {
43             return true;
44         }
45         if (other == null || getClass() != other.getClass()) {
46             return false;
47         }
48         if (!super.equals(other)) {
49             return false;
50         }
51
52         MatchTcpDestinationPort that = (MatchTcpDestinationPort) other;
53
54         return port == that.port;
55     }
56
57     @Override
58     public int hashCode() {
59         int result = super.hashCode();
60         result = 31 * result + port;
61         return result;
62     }
63
64     @Override
65     public String toString() {
66         return "MatchTcpDestinationPort[" + port + "]";
67     }
68
69 }