Merge "Load config system files in etc/opendaylight/karaf"
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / ActionInfo.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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;
9
10 import com.google.common.base.MoreObjects;
11 import java.io.Serializable;
12 import java.math.BigInteger;
13 import java.util.Arrays;
14 import java.util.Objects;
15 import org.opendaylight.genius.utils.MoreObjects2;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
17
18 public class ActionInfo implements Serializable {
19
20     private static final long serialVersionUID = 1L;
21
22     private final ActionType m_actionType;
23
24     private String[] m_asActionValues = null;
25     private BigInteger[] m_aBigIntValues;
26     private int m_actionKey = 0;
27
28     public ActionInfo(ActionInfo action) {
29         super();
30         m_actionType = action.m_actionType;
31         m_actionKey = action.m_actionKey;
32         m_asActionValues = Arrays.copyOf(action.m_asActionValues, action.m_asActionValues.length);
33     }
34
35     public ActionInfo(ActionType actionType, String[] asActionValues) {
36         m_actionType = actionType;
37         m_actionKey = 0;
38         m_asActionValues = asActionValues;
39     }
40
41     public ActionInfo(ActionType actionType, String[] asActionValues, int actionKey) {
42         m_actionType = actionType;
43         m_actionKey = actionKey;
44         m_asActionValues = asActionValues;
45     }
46
47     public ActionInfo(ActionType actionType, BigInteger[] aBigIntValues) {
48         m_actionType = actionType;
49         m_actionKey = 0;
50         m_aBigIntValues = aBigIntValues;
51     }
52
53     public ActionInfo(ActionType actionType, BigInteger[] aBigIntValues, int actionKey) {
54         m_actionType = actionType;
55         m_actionKey = actionKey;
56         m_aBigIntValues = aBigIntValues;
57     }
58
59     public void setActionKey(int key) {
60         m_actionKey = key;
61     }
62
63     public int getActionKey() {
64         return m_actionKey;
65     }
66
67     public Action buildAction() {
68         return m_actionType.buildAction(this);
69     }
70
71     public ActionType getActionType() {
72         return m_actionType;
73     }
74
75     public String[] getActionValues() {
76         return m_asActionValues;
77     }
78
79     public BigInteger[] getBigActionValues() {
80         return m_aBigIntValues;
81     }
82
83     @Override
84     public String toString() {
85         return MoreObjects.toStringHelper(this).omitNullValues().add("actionType", m_actionType)
86                 .add("actionValues", Arrays.deepToString(m_asActionValues))
87                 .add("bigActionValues", Arrays.deepToString(m_aBigIntValues))
88                 .add("actionKey", m_actionKey).toString();
89     }
90
91     @Override
92     public int hashCode() {
93         // BEWARE, Caveat Emptor: Array ([]) type fields must use
94         // Arrays.hashCode(). deepHashCode() would have to be used for nested
95         // arrays.
96         return Objects.hash(m_actionType, Arrays.hashCode(m_asActionValues), Arrays.hashCode(m_aBigIntValues),
97                 m_actionKey);
98     }
99
100     @Override
101     public boolean equals(Object obj) {
102         // BEWARE, Caveat Emptor: Array ([]) type fields must use
103         // Arrays.equals(). deepEquals() would have to be used for nested
104         // arrays. Use == only for primitive types; if ever changing
105         // those field types, must change to Objects.equals.
106         return MoreObjects2.equalsHelper(this, obj,
107             (self, other) -> Objects.equals(self.m_actionType, other.m_actionType)
108                           && Arrays.equals(self.m_asActionValues, other.m_asActionValues)
109                           && Arrays.equals(self.m_aBigIntValues, other.m_aBigIntValues)
110                           && self.m_actionKey == other.m_actionKey);
111     }
112 }