blob: 98a89288e6f75494baf29c0c87c49619e62177a6 [file] [log] [blame]
Charles Chanb87d9f12018-10-31 21:00:06 -07001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.net.flowobjective;
17
18import java.util.Objects;
19
20import static com.google.common.base.MoreObjects.toStringHelper;
21
22/**
23 * Represents a next action specified by next id.
24 */
25public final class IdNextTreatment implements NextTreatment {
26 private final int nextId;
27
28 /**
29 * Constructs IdNextTreatment.
30 *
31 * @param nextId next id
32 */
33 private IdNextTreatment(int nextId) {
34 this.nextId = nextId;
35 }
36
37 /**
38 * Returns next id.
39 *
40 * @return next id
41 */
42 public int nextId() {
43 return nextId;
44 }
45
46 /**
47 * Returns an instance of IdNextTreatment with given next id.
48 *
49 * @param nextId next id
50 * @return an instance of IdNextTreatment
51 */
52 public static IdNextTreatment of(int nextId) {
53 return new IdNextTreatment(nextId);
54 }
55
56 @Override
57 public Type type() {
58 return Type.ID;
59 }
60 @Override
61 public int hashCode() {
62 return Objects.hash(nextId);
63 }
64
65 @Override
66 public boolean equals(Object obj) {
67 if (this == obj) {
68 return true;
69 }
70 if (obj instanceof IdNextTreatment) {
71 final IdNextTreatment other = (IdNextTreatment) obj;
72 return this.nextId == other.nextId;
73 }
74 return false;
75 }
76
77 @Override
78 public String toString() {
79 return toStringHelper(this)
80 .add("nextId", nextId)
81 .toString();
82 }
83}