blob: a442586846210d4e81b6a28731fe5f7f996efab4 [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 NepRef pair class for representation of endpoints of single connection.
26 */
27public class TapiNepPair {
28
29 private TapiNepRef left;
30 private TapiNepRef right;
31
32 public TapiNepPair() {
33 }
34
35 public static TapiNepPair create(TapiNepRef left, TapiNepRef right) {
36 TapiNepPair self = new TapiNepPair();
37 self.left = left;
38 self.right = right;
39 return self;
40 }
41
42 public TapiNepRef left() {
43 return left;
44 }
45
46 public TapiNepRef right() {
47 return right;
48 }
49
50 public TapiNepPair invert() {
51 return TapiNepPair.create(right, left);
52 }
53
54 public boolean isSameNode() {
55 return left.getTopologyId().equals(right.getTopologyId()) && left.getNodeId().equals(right.getNodeId());
56 }
57
58 public Stream<TapiNepRef> stream() {
59 return Stream.of(left, right);
60 }
61
62 public String toString() {
63 return toStringHelper(getClass())
64 .add("left", left)
65 .add("right", right)
66 .toString();
67 }
68
69 @Override
70 public boolean equals(Object o) {
71 if (this == o) {
72 return true;
73 }
74 if (!(o instanceof TapiNepPair)) {
75 return false;
76 }
77 TapiNepPair that = (TapiNepPair) o;
78 return Objects.equals(left, that.left) &&
79 Objects.equals(right, that.right);
80 }
81
82 @Override
83 public int hashCode() {
84 return Objects.hash(left, right);
85 }
86}