Merge "Simplify boolean expressions"
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionSetUdpDestinationPort.java
1 /*
2  * Copyright © 2016 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.actions;
9
10 import org.opendaylight.genius.mdsalutil.ActionInfo;
11 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.layer._4.match.UdpMatchBuilder;
18
19 /**
20  * Set UDP destination port action.
21  */
22 public class ActionSetUdpDestinationPort extends ActionInfo {
23     private static final long serialVersionUID = 1L;
24
25     private final int port;
26
27     public ActionSetUdpDestinationPort(int port) {
28         this(0, port);
29     }
30
31     public ActionSetUdpDestinationPort(int actionKey, int port) {
32         super(actionKey);
33         this.port = port;
34     }
35
36     @Override
37     public Action buildAction() {
38         return buildAction(getActionKey());
39     }
40
41     @Override
42     public Action buildAction(int newActionKey) {
43         return new ActionBuilder()
44             .setAction(new SetFieldCaseBuilder()
45                 .setSetField(new SetFieldBuilder()
46                     .setLayer4Match(new UdpMatchBuilder()
47                         .setUdpDestinationPort(new PortNumber(port)).build())
48                     .build())
49                 .build())
50             .setKey(new ActionKey(newActionKey))
51             .build();
52     }
53
54     public int getPort() {
55         return port;
56     }
57
58     @Override
59     public boolean equals(Object other) {
60         if (this == other) {
61             return true;
62         }
63         if (other == null || getClass() != other.getClass()) {
64             return false;
65         }
66         if (!super.equals(other)) {
67             return false;
68         }
69
70         ActionSetUdpDestinationPort that = (ActionSetUdpDestinationPort) other;
71
72         return port == that.port;
73     }
74
75     @Override
76     public int hashCode() {
77         int result = super.hashCode();
78         result = 31 * result + port;
79         return result;
80     }
81 }