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