blob: 8b473612db7f7ca662b7c0ad02f1ef05a31c42be [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;
Niloofar Toorchi8bbe9ca2021-07-30 14:08:04 -070027 private final int weight;
Charles Chanb87d9f12018-10-31 21:00:06 -070028
29 /**
30 * Constructs IdNextTreatment.
31 *
32 * @param nextId next id
Niloofar Toorchi8bbe9ca2021-07-30 14:08:04 -070033 * @param weight weight
Charles Chanb87d9f12018-10-31 21:00:06 -070034 */
Niloofar Toorchi8bbe9ca2021-07-30 14:08:04 -070035 private IdNextTreatment(int nextId, int weight) {
Charles Chanb87d9f12018-10-31 21:00:06 -070036 this.nextId = nextId;
Niloofar Toorchi8bbe9ca2021-07-30 14:08:04 -070037 this.weight = weight;
Charles Chanb87d9f12018-10-31 21:00:06 -070038 }
39
40 /**
41 * Returns next id.
42 *
43 * @return next id
44 */
45 public int nextId() {
46 return nextId;
47 }
48
49 /**
50 * Returns an instance of IdNextTreatment with given next id.
51 *
52 * @param nextId next id
53 * @return an instance of IdNextTreatment
54 */
55 public static IdNextTreatment of(int nextId) {
Niloofar Toorchi8bbe9ca2021-07-30 14:08:04 -070056 return new IdNextTreatment(nextId, DEFAULT_WEIGHT);
57 }
58 /**
59 * Returns an instance of IdNextTreatment with given next id and weight.
60 *
61 * @param nextId next id
62 * @param weight weight
63 * @return an instance of IdNextTreatment
64 */
65 public static IdNextTreatment of(int nextId, int weight) {
66 return new IdNextTreatment(nextId, weight);
67 }
68
69 @Override
70 public int weight() {
71 return weight;
Charles Chanb87d9f12018-10-31 21:00:06 -070072 }
73
74 @Override
75 public Type type() {
76 return Type.ID;
77 }
78 @Override
79 public int hashCode() {
Niloofar Toorchi8bbe9ca2021-07-30 14:08:04 -070080 return Objects.hash(nextId, weight);
Charles Chanb87d9f12018-10-31 21:00:06 -070081 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj) {
86 return true;
87 }
88 if (obj instanceof IdNextTreatment) {
89 final IdNextTreatment other = (IdNextTreatment) obj;
Niloofar Toorchi8bbe9ca2021-07-30 14:08:04 -070090 return this.nextId == other.nextId && this.weight == other.weight;
Charles Chanb87d9f12018-10-31 21:00:06 -070091 }
92 return false;
93 }
94
95 @Override
96 public String toString() {
97 return toStringHelper(this)
98 .add("nextId", nextId)
Niloofar Toorchi8bbe9ca2021-07-30 14:08:04 -070099 .add("weight", weight)
Charles Chanb87d9f12018-10-31 21:00:06 -0700100 .toString();
101 }
102}