Make ActionInfo immutable
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / InstructionInfo.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.List;
15
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
17
18 public class InstructionInfo extends AbstractActionInfoList implements Serializable {
19
20     private static final long serialVersionUID = 1L;
21
22     private final InstructionType m_instructionType;
23     private final long[] m_alInstructionValues;
24     private final BigInteger[] m_alBigInstructionValues;
25
26     // This constructor should be used incase of clearAction
27     public InstructionInfo(InstructionType instructionType) {
28         super(null);
29         m_instructionType = instructionType;
30         m_alInstructionValues = null;
31         m_alBigInstructionValues = null;
32     }
33
34     public InstructionInfo(InstructionType instructionType, long[] instructionValues) {
35         super(null);
36         m_instructionType = instructionType;
37         m_alInstructionValues = instructionValues;
38         m_alBigInstructionValues = null;
39     }
40
41     public InstructionInfo(InstructionType instructionType, BigInteger[] instructionValues) {
42         super(null);
43         m_instructionType = instructionType;
44         m_alInstructionValues = null;
45         m_alBigInstructionValues = instructionValues;
46     }
47
48     public InstructionInfo(InstructionType instructionType, List<ActionInfo> actionInfos) {
49         super(actionInfos);
50         m_instructionType = instructionType;
51         m_alInstructionValues = null;
52         m_alBigInstructionValues = null;
53     }
54
55     public Instruction buildInstruction(int instructionKey) {
56         return m_instructionType.buildInstruction(this, instructionKey);
57     }
58
59     public InstructionType getInstructionType() {
60         return m_instructionType;
61     }
62
63     public long[] getInstructionValues() {
64         return m_alInstructionValues;
65     }
66
67     public BigInteger[] getBigInstructionValues() {
68         return m_alBigInstructionValues;
69     }
70
71     @Override
72     public String toString() {
73         return MoreObjects.toStringHelper(this).omitNullValues().add("instructionType", m_instructionType)
74                 .add("instructionValues", Arrays.toString(m_alInstructionValues))
75                 .add("bigInstructionValues", Arrays.deepToString(m_alBigInstructionValues))
76                 .add("actionInfos", getActionInfos()).toString();
77     }
78 }