Charles Chan | b87d9f1 | 2018-10-31 21:00:06 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.net.flowobjective; |
| 17 | |
| 18 | import java.util.Objects; |
| 19 | |
| 20 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 21 | |
| 22 | /** |
| 23 | * Represents a next action specified by next id. |
| 24 | */ |
| 25 | public final class IdNextTreatment implements NextTreatment { |
| 26 | private final int nextId; |
Niloofar Toorchi | 8bbe9ca | 2021-07-30 14:08:04 -0700 | [diff] [blame] | 27 | private final int weight; |
Charles Chan | b87d9f1 | 2018-10-31 21:00:06 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Constructs IdNextTreatment. |
| 31 | * |
| 32 | * @param nextId next id |
Niloofar Toorchi | 8bbe9ca | 2021-07-30 14:08:04 -0700 | [diff] [blame] | 33 | * @param weight weight |
Charles Chan | b87d9f1 | 2018-10-31 21:00:06 -0700 | [diff] [blame] | 34 | */ |
Niloofar Toorchi | 8bbe9ca | 2021-07-30 14:08:04 -0700 | [diff] [blame] | 35 | private IdNextTreatment(int nextId, int weight) { |
Charles Chan | b87d9f1 | 2018-10-31 21:00:06 -0700 | [diff] [blame] | 36 | this.nextId = nextId; |
Niloofar Toorchi | 8bbe9ca | 2021-07-30 14:08:04 -0700 | [diff] [blame] | 37 | this.weight = weight; |
Charles Chan | b87d9f1 | 2018-10-31 21:00:06 -0700 | [diff] [blame] | 38 | } |
| 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 Toorchi | 8bbe9ca | 2021-07-30 14:08:04 -0700 | [diff] [blame] | 56 | 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 Chan | b87d9f1 | 2018-10-31 21:00:06 -0700 | [diff] [blame] | 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public Type type() { |
| 76 | return Type.ID; |
| 77 | } |
| 78 | @Override |
| 79 | public int hashCode() { |
Niloofar Toorchi | 8bbe9ca | 2021-07-30 14:08:04 -0700 | [diff] [blame] | 80 | return Objects.hash(nextId, weight); |
Charles Chan | b87d9f1 | 2018-10-31 21:00:06 -0700 | [diff] [blame] | 81 | } |
| 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 Toorchi | 8bbe9ca | 2021-07-30 14:08:04 -0700 | [diff] [blame] | 90 | return this.nextId == other.nextId && this.weight == other.weight; |
Charles Chan | b87d9f1 | 2018-10-31 21:00:06 -0700 | [diff] [blame] | 91 | } |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public String toString() { |
| 97 | return toStringHelper(this) |
| 98 | .add("nextId", nextId) |
Niloofar Toorchi | 8bbe9ca | 2021-07-30 14:08:04 -0700 | [diff] [blame] | 99 | .add("weight", weight) |
Charles Chan | b87d9f1 | 2018-10-31 21:00:06 -0700 | [diff] [blame] | 100 | .toString(); |
| 101 | } |
| 102 | } |