2 * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. and others. All rights reserved.
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
8 package org.opendaylight.genius.mdsalutil;
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;
18 public class ActionInfo implements Serializable {
20 private static final long serialVersionUID = 1L;
22 private final ActionType m_actionType;
23 private final String[] m_asActionValues;
24 private final BigInteger[] m_aBigIntValues;
25 private final int m_actionKey;
27 public ActionInfo(ActionInfo action) {
29 m_actionType = action.m_actionType;
30 m_actionKey = action.m_actionKey;
31 m_asActionValues = Arrays.copyOf(action.m_asActionValues, action.m_asActionValues.length);
32 m_aBigIntValues = null;
35 public ActionInfo(ActionType actionType, String[] asActionValues) {
36 m_actionType = actionType;
38 m_asActionValues = asActionValues;
39 m_aBigIntValues = null;
42 public ActionInfo(ActionType actionType, String[] asActionValues, int actionKey) {
43 m_actionType = actionType;
44 m_actionKey = actionKey;
45 m_asActionValues = asActionValues;
46 m_aBigIntValues = null;
49 public ActionInfo(ActionType actionType, BigInteger[] aBigIntValues) {
50 m_actionType = actionType;
52 m_aBigIntValues = aBigIntValues;
53 m_asActionValues = null;
56 public ActionInfo(ActionType actionType, BigInteger[] aBigIntValues, int actionKey) {
57 m_actionType = actionType;
58 m_actionKey = actionKey;
59 m_aBigIntValues = aBigIntValues;
60 m_asActionValues = null;
63 public int getActionKey() {
67 public Action buildAction() {
68 return m_actionType.buildAction(getActionKey(), this);
71 public ActionType getActionType() {
75 public String[] getActionValues() {
76 return m_asActionValues;
79 public BigInteger[] getBigActionValues() {
80 return m_aBigIntValues;
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();
92 public int hashCode() {
93 // BEWARE, Caveat Emptor: Array ([]) type fields must use
94 // Arrays.hashCode(). deepHashCode() would have to be used for nested
96 return Objects.hash(m_actionType, Arrays.hashCode(m_asActionValues), Arrays.hashCode(m_aBigIntValues),
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);