Freeze upstream versions
[genius.git] / mdsalutil / mdsalutil-api / src / main / java / org / opendaylight / genius / mdsalutil / instructions / InstructionGotoTable.java
1 /*
2  * Copyright © 2017 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.instructions;
9
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
15
16 /**
17  * Goto table instruction.
18  */
19 public class InstructionGotoTable extends AbstractInstructionInfoImpl {
20
21     private final short tableId;
22
23     public InstructionGotoTable(short tableId) {
24         this.tableId = tableId;
25     }
26
27     @Override
28     public Instruction buildInstruction(int instructionKey) {
29         return new InstructionBuilder()
30                 .setInstruction(new GoToTableCaseBuilder()
31                         .setGoToTable(new GoToTableBuilder()
32                                 .setTableId(tableId)
33                                 .build()
34                         )
35                         .build()
36                 )
37                 .withKey(new InstructionKey(instructionKey))
38                 .build();
39     }
40
41     public short getTableId() {
42         return tableId;
43     }
44
45     @Override
46     public boolean equals(Object other) {
47         if (this == other) {
48             return true;
49         }
50         if (other == null || getClass() != other.getClass()) {
51             return false;
52         }
53
54         InstructionGotoTable that = (InstructionGotoTable) other;
55
56         return tableId == that.tableId;
57     }
58
59     @Override
60     public int hashCode() {
61         return tableId;
62     }
63
64     @Override
65     public String toString() {
66         return "InstructionGotoTable[" + tableId + "]";
67     }
68 }