Satish K | d70e957 | 2016-04-28 13:58:51 +0530 | [diff] [blame] | 1 | /* |
Thomas Vachuska | 52f2cd1 | 2018-11-08 21:20:04 -0800 | [diff] [blame^] | 2 | * Copyright 2018-present Open Networking Foundation |
Satish K | d70e957 | 2016-04-28 13:58:51 +0530 | [diff] [blame] | 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 | package org.onosproject.incubator.net.tunnel; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | import org.onosproject.incubator.net.resource.label.LabelResourceId; |
| 21 | import java.util.List; |
| 22 | import java.util.Objects; |
| 23 | |
| 24 | /** |
| 25 | * Default implementation of label stack. |
| 26 | */ |
| 27 | public class DefaultLabelStack implements LabelStack { |
| 28 | |
| 29 | private final List<LabelResourceId> labelResources; |
| 30 | |
| 31 | /** |
| 32 | * Creates label stack. |
| 33 | * |
| 34 | * @param labelResources contiguous label ids that comprise the path |
| 35 | */ |
| 36 | public DefaultLabelStack(List<LabelResourceId> labelResources) { |
| 37 | this.labelResources = ImmutableList.copyOf(labelResources); |
| 38 | } |
| 39 | |
| 40 | @Override |
| 41 | public List<LabelResourceId> labelResources() { |
| 42 | return labelResources; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public String toString() { |
| 47 | return MoreObjects.toStringHelper(this) |
| 48 | .add("labelResources", labelResources) |
| 49 | .toString(); |
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public int hashCode() { |
| 54 | return labelResources.hashCode(); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public boolean equals(Object obj) { |
| 59 | if (this == obj) { |
| 60 | return true; |
| 61 | } |
| 62 | if (obj instanceof DefaultLabelStack) { |
| 63 | final DefaultLabelStack other = (DefaultLabelStack) obj; |
| 64 | return Objects.equals(this.labelResources, other.labelResources); |
| 65 | } |
| 66 | return false; |
| 67 | } |
| 68 | } |