blob: f283bf3a046625134cdeb051b0ee26e6e91a86b9 [file] [log] [blame]
hirokif4ed5212018-05-26 22:39:38 -07001/*
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.odtn.utils.tapi;
18
19import java.util.Objects;
20import java.util.stream.Stream;
21
22import static com.google.common.base.MoreObjects.toStringHelper;
23
24/**
25 * TAPI CepRef pair class for representation of endpoints of single connection.
26 */
27public final class TapiCepPair {
28
29 private TapiCepRef left;
30 private TapiCepRef right;
31
32 private TapiCepPair() {
33 }
34
35 public static TapiCepPair create(TapiCepRef left, TapiCepRef right) {
36 TapiCepPair self = new TapiCepPair();
37 self.left = left;
38 self.right = right;
39 return self;
40 }
41
42 public TapiCepRef left() {
43 return left;
44 }
45
46 public TapiCepRef right() {
47 return right;
48 }
49
50 public TapiNepPair getTapiNepPair() {
51 return TapiNepPair.create(left.getNepRef(), right.getNepRef());
52 }
53
54 public TapiCepPair invert() {
55 return TapiCepPair.create(right, left);
56 }
57
58 public boolean isSameNode() {
59 return left.getTopologyId().equals(right.getTopologyId()) && left.getNodeId().equals(right.getNodeId());
60 }
61
62 public Stream<TapiCepRef> stream() {
63 return Stream.of(left, right);
64 }
65
66 public String toString() {
67 return toStringHelper(getClass())
68 .add("left", left)
69 .add("right", right)
70 .toString();
71 }
72
73 @Override
74 public boolean equals(Object o) {
75 if (this == o) {
76 return true;
77 }
78 if (!(o instanceof TapiCepPair)) {
79 return false;
80 }
81 TapiCepPair that = (TapiCepPair) o;
82 return Objects.equals(left, that.left) &&
83 Objects.equals(right, that.right);
84 }
85
86 @Override
87 public int hashCode() {
88 return Objects.hash(left, right);
89 }
90}