blob: ff4e172eb502ce09deb854a3304b4aa12a58c6b7 [file] [log] [blame]
FrankWangea70de32018-05-08 15:41:25 +08001/*
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
17package org.onosproject.net.pi.runtime.data;
18
19import com.google.common.annotations.Beta;
20import com.google.common.base.Objects;
21import org.onosproject.net.pi.model.PiData;
22
23/**
24 * ErrorString entity in a protocol-independent pipeline.
25 */
26@Beta
27public final class PiErrorString implements PiData {
28 private final String errorString;
29
30 /**
31 * Creates a new protocol-independent error string instance.
32 *
33 * @param errorString error string
34 */
35 private PiErrorString(String errorString) {
36 this.errorString = errorString;
37 }
38
39 /**
40 * Returns a new protocol-independent error string.
41 * @param errorString error string
42 * @return error string
43 */
44 public static PiErrorString of(String errorString) {
45 return new PiErrorString(errorString);
46 }
47
48 /**
49 * Return protocol-independent error string instance.
50 *
51 * @return error string
52 */
53 public String errorString() {
54 return this.errorString;
55 }
56
57 @Override
58 public Type type() {
59 return Type.ERRORSTRING;
60 }
61
62 @Override
63 public boolean equals(Object o) {
64 if (this == o) {
65 return true;
66 }
67 if (o == null || getClass() != o.getClass()) {
68 return false;
69 }
70 PiErrorString errorStr = (PiErrorString) o;
71 return Objects.equal(errorString, errorStr.errorString);
72 }
73
74 @Override
75 public int hashCode() {
76 return Objects.hashCode(errorString);
77 }
78
79 @Override
80 public String toString() {
81 return errorString;
82 }
83}