Action redesign: drop obsolete code
[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 final BigInteger tunnelId;
25     @Nullable private final BigInteger tunnelMask;
26
27     public ActionSetFieldTunnelId(BigInteger tunnelId) {
28         this(0, tunnelId);
29     }
30
31     public ActionSetFieldTunnelId(int actionKey, BigInteger tunnelId) {
32         this(actionKey, tunnelId, null);
33     }
34
35     public ActionSetFieldTunnelId(BigInteger tunnelId, BigInteger tunnelMask) {
36         this(0, tunnelId, tunnelMask);
37     }
38
39     public ActionSetFieldTunnelId(int actionKey, BigInteger tunnelId, BigInteger tunnelMask) {
40         super(actionKey);
41         this.tunnelId = tunnelId;
42         this.tunnelMask = tunnelMask;
43     }
44
45     @Override
46     public Action buildAction() {
47         return buildAction(getActionKey());
48     }
49
50     public Action buildAction(int newActionKey) {
51         TunnelBuilder tunnelBuilder = new TunnelBuilder()
52             .setTunnelId(tunnelId);
53         if (tunnelMask != null) {
54             tunnelBuilder.setTunnelMask(tunnelMask);
55         }
56         return new ActionBuilder()
57             .setAction(
58                 new SetFieldCaseBuilder()
59                     .setSetField(
60                         new SetFieldBuilder()
61                             .setTunnel(tunnelBuilder.build())
62                             .build())
63                     .build())
64             .setKey(new ActionKey(newActionKey))
65             .build();
66     }
67
68     public BigInteger getTunnelId() {
69         return tunnelId;
70     }
71
72     @Nullable
73     public BigInteger getTunnelMask() {
74         return tunnelMask;
75     }
76
77     @Override
78     public boolean equals(Object o) {
79         if (this == o) return true;
80         if (o == null || getClass() != o.getClass()) return false;
81         if (!super.equals(o)) return false;
82
83         ActionSetFieldTunnelId that = (ActionSetFieldTunnelId) o;
84
85         if (tunnelId != null ? !tunnelId.equals(that.tunnelId) : that.tunnelId != null) return false;
86         return tunnelMask != null ? tunnelMask.equals(that.tunnelMask) : that.tunnelMask == null;
87     }
88
89     @Override
90     public int hashCode() {
91         int result = super.hashCode();
92         result = 31 * result + (tunnelId != null ? tunnelId.hashCode() : 0);
93         result = 31 * result + (tunnelMask != null ? tunnelMask.hashCode() : 0);
94         return result;
95     }
96 }