blob: 4387b56575955a5f7bde315efa5500b2e968ec17 [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 org.onosproject.net.flow.TrafficTreatment;
19
20import java.util.Objects;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
25 * Represents a next action specified by traffic treatment.
26 */
27public final class DefaultNextTreatment implements NextTreatment {
28 private final TrafficTreatment treatment;
29
30 private DefaultNextTreatment(TrafficTreatment treatment) {
31 this.treatment = treatment;
32 }
33
34 /**
35 * Returns traffic treatment.
36 *
37 * @return traffic treatment.
38 */
39 public TrafficTreatment treatment() {
40 return treatment;
41 }
42
43 /**
44 * Returns an instance of DefaultNextTreatment with given traffic treatment.
45 *
46 * @param treatment traffic treatment
47 * @return an instance of DefaultNextTreatment
48 */
49 public static DefaultNextTreatment of(TrafficTreatment treatment) {
50 return new DefaultNextTreatment(treatment);
51 }
52
53 @Override
54 public Type type() {
55 return Type.TREATMENT;
56 }
57
58 @Override
59 public int hashCode() {
60 return Objects.hash(treatment);
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (this == obj) {
66 return true;
67 }
68 if (obj instanceof DefaultNextTreatment) {
69 final DefaultNextTreatment other = (DefaultNextTreatment) obj;
70 return Objects.equals(this.treatment, other.treatment);
71 }
72 return false;
73 }
74
75 @Override
76 public String toString() {
77 return toStringHelper(this)
78 .add("treatment", treatment)
79 .toString();
80 }
81}