blob: 7c60c16c280a2acd538ec85fd5e95e1f365ce37e [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 com.google.common.collect.ImmutableList;
22import org.onosproject.net.pi.model.PiData;
23
24import java.util.List;
25import java.util.StringJoiner;
26
27/**
28 * Struct entity in a protocol-independent pipeline.
29 */
30@Beta
31public final class PiStruct implements PiData {
32 private final ImmutableList<PiData> struct;
33
34 /**
35 * Creates a new protocol-independent struct instance for the given collection of PiData.
36 *
37 * @param struct the collection of PiData
38 */
39 private PiStruct(List<PiData> struct) {
40 this.struct = ImmutableList.copyOf(struct);
41 }
42
43 /**
44 * Returns a new protocol-independent struct.
45 * @param struct the list of PiData
46 * @return struct
47 */
48 public static PiStruct of(List<PiData> struct) {
49 return new PiStruct(struct);
50 }
51
52 /**
53 * Return protocol-independent struct instance.
54 *
55 * @return the list of PiData
56 */
57 public List<PiData> struct() {
58 return this.struct;
59 }
60
61 @Override
62 public Type type() {
63 return Type.STRUCT;
64 }
65
66 @Override
67 public boolean equals(Object o) {
68 if (this == o) {
69 return true;
70 }
71 if (o == null || getClass() != o.getClass()) {
72 return false;
73 }
74 PiStruct st = (PiStruct) o;
75 return Objects.equal(struct, st.struct);
76 }
77
78 @Override
79 public int hashCode() {
80 return Objects.hashCode(struct);
81 }
82
83 @Override
84 public String toString() {
85 StringJoiner stringParams = new StringJoiner(", ", "(", ")");
86 this.struct().forEach(p -> stringParams.add(p.toString()));
87 return stringParams.toString();
88 }
89}