blob: 74481ead2c7274b1a3254eaf1a9dd212f9d2f2c1 [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 * EnumString entity in a protocol-independent pipeline.
25 */
26@Beta
27public final class PiEnumString implements PiData {
28 private final String enumString;
29
30 /**
31 * Creates a new protocol-independent enum string instance.
32 *
33 * @param enumString enum string
34 */
35 private PiEnumString(String enumString) {
36 this.enumString = enumString;
37 }
38
39 /**
40 * Returns a new protocol-independent enum string.
41 * @param enumString enum string
42 * @return enum string
43 */
44 public static PiEnumString of(String enumString) {
45 return new PiEnumString(enumString);
46 }
47
48 /**
49 * Return protocol-independent enum string instance.
50 *
51 * @return enum string
52 */
53 public String enumString() {
54 return this.enumString;
55 }
56
57 @Override
58 public Type type() {
59 return Type.ENUMSTRING;
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 PiEnumString enumStr = (PiEnumString) o;
71 return Objects.equal(enumString, enumStr.enumString);
72 }
73
74 @Override
75 public int hashCode() {
76 return Objects.hashCode(enumString);
77 }
78
79 @Override
80 public String toString() {
81 return enumString;
82 }
83}