Instruction redesign: add missing equals/hashCode
[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.genius.mdsalutil.InstructionInfo;
11 import org.opendaylight.genius.mdsalutil.InstructionType;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.GoToTableCaseBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.instruction.go.to.table._case.GoToTableBuilder;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionBuilder;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.InstructionKey;
17
18 /**
19  * Goto table instruction.
20  */
21 public class InstructionGotoTable extends InstructionInfo {
22     private final short tableId;
23
24     public InstructionGotoTable(short tableId) {
25         super(InstructionType.goto_table, new long[] {tableId});
26         this.tableId = tableId;
27     }
28
29     @Override
30     public Instruction buildInstruction(int instructionKey) {
31         return new InstructionBuilder()
32                 .setInstruction(new GoToTableCaseBuilder()
33                         .setGoToTable(new GoToTableBuilder()
34                                 .setTableId(tableId)
35                                 .build()
36                         )
37                         .build()
38                 )
39                 .setKey(new InstructionKey(instructionKey))
40                 .build();
41     }
42
43     @Override
44     public boolean equals(Object o) {
45         if (this == o) return true;
46         if (o == null || getClass() != o.getClass()) return false;
47
48         InstructionGotoTable that = (InstructionGotoTable) o;
49
50         return tableId == that.tableId;
51     }
52
53     @Override
54     public int hashCode() {
55         return (int) tableId;
56     }
57 }