blob: 1c7ff8c741037e12e83ffb8b157d84a73682f987 [file] [log] [blame]
Satish Kd70e9572016-04-28 13:58:51 +05301/*
Thomas Vachuska52f2cd12018-11-08 21:20:04 -08002 * Copyright 2018-present Open Networking Foundation
Satish Kd70e9572016-04-28 13:58:51 +05303 *
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 */
16package org.onosproject.incubator.net.tunnel;
17
18import com.google.common.base.MoreObjects;
19import com.google.common.collect.ImmutableList;
20import org.onosproject.incubator.net.resource.label.LabelResourceId;
21import java.util.List;
22import java.util.Objects;
23
24/**
25 * Default implementation of label stack.
26 */
27public 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}