Add missing @Override and serialVersionUID to genius.mdsalutil
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / actions / ActionSetFieldTunnelId.java
1 /*
2  * Copyright (c) 2016 Red Hat, Inc. 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 package org.opendaylight.genius.mdsalutil.actions;
9
10 import java.math.BigInteger;
11 import javax.annotation.Nullable;
12 import org.opendaylight.genius.mdsalutil.ActionInfo;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetFieldCaseBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.set.field._case.SetFieldBuilder;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.ActionKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.TunnelBuilder;
19
20 /**
21  * Set tunnel id field action.
22  */
23 public class ActionSetFieldTunnelId extends ActionInfo {
24     private static final long serialVersionUID = 1L;
25
26     private final BigInteger tunnelId;
27     @Nullable private final BigInteger tunnelMask;
28
29     public ActionSetFieldTunnelId(BigInteger tunnelId) {
30         this(0, tunnelId);
31     }
32
33     public ActionSetFieldTunnelId(int actionKey, BigInteger tunnelId) {
34         this(actionKey, tunnelId, null);
35     }
36
37     public ActionSetFieldTunnelId(BigInteger tunnelId, BigInteger tunnelMask) {
38         this(0, tunnelId, tunnelMask);
39     }
40
41     public ActionSetFieldTunnelId(int actionKey, BigInteger tunnelId, BigInteger tunnelMask) {
42         super(actionKey);
43         this.tunnelId = tunnelId;
44         this.tunnelMask = tunnelMask;
45     }
46
47     @Override
48     public Action buildAction() {
49         return buildAction(getActionKey());
50     }
51
52     @Override
53     public Action buildAction(int newActionKey) {
54         TunnelBuilder tunnelBuilder = new TunnelBuilder()
55             .setTunnelId(tunnelId);
56         if (tunnelMask != null) {
57             tunnelBuilder.setTunnelMask(tunnelMask);
58         }
59         return new ActionBuilder()
60             .setAction(
61                 new SetFieldCaseBuilder()
62                     .setSetField(
63                         new SetFieldBuilder()
64                             .setTunnel(tunnelBuilder.build())
65                             .build())
66                     .build())
67             .setKey(new ActionKey(newActionKey))
68             .build();
69     }
70
71     public BigInteger getTunnelId() {
72         return tunnelId;
73     }
74
75     @Nullable
76     public BigInteger getTunnelMask() {
77         return tunnelMask;
78     }
79
80     @Override
81     public boolean equals(Object other) {
82         if (this == other) {
83             return true;
84         }
85         if (other == null || getClass() != other.getClass()) {
86             return false;
87         }
88         if (!super.equals(other)) {
89             return false;
90         }
91
92         ActionSetFieldTunnelId that = (ActionSetFieldTunnelId) other;
93
94         if (tunnelId != null ? !tunnelId.equals(that.tunnelId) : that.tunnelId != null) {
95             return false;
96         }
97         return tunnelMask != null ? tunnelMask.equals(that.tunnelMask) : that.tunnelMask == null;
98     }
99
100     @Override
101     public int hashCode() {
102         int result = super.hashCode();
103         result = 31 * result + (tunnelId != null ? tunnelId.hashCode() : 0);
104         result = 31 * result + (tunnelMask != null ? tunnelMask.hashCode() : 0);
105         return result;
106     }
107 }