blob: 249c88f39f647dcd3f157010f5b8fc8e0b7df10f [file] [log] [blame]
Aihua Guo1ce2dd12016-08-12 23:37:44 -04001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016 Open Networking Foundation
Aihua Guo1ce2dd12016-08-12 23:37:44 -04003 *
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.tetopology.management.api.node;
17
Henry Yu4b4a7eb2016-11-09 20:07:53 -050018import com.google.common.base.Objects;
Aihua Guo1ce2dd12016-08-12 23:37:44 -040019import org.onosproject.tetopology.management.api.KeyId;
20
Henry Yu4b4a7eb2016-11-09 20:07:53 -050021import static com.google.common.base.MoreObjects.toStringHelper;
Aihua Guo1ce2dd12016-08-12 23:37:44 -040022
23/**
24 * Representation of a termination point key or reference.
25 */
26public class TerminationPointKey extends NetworkNodeKey {
27 private final KeyId tpId;
28
29 /**
Henry Yu4b4a7eb2016-11-09 20:07:53 -050030 * Creates a termination point key.
Aihua Guo1ce2dd12016-08-12 23:37:44 -040031 *
32 * @param networkId network identifier
Henry Yu4b4a7eb2016-11-09 20:07:53 -050033 * @param nodeId node identifier
34 * @param tpId termination point identifier
Aihua Guo1ce2dd12016-08-12 23:37:44 -040035 */
36 public TerminationPointKey(KeyId networkId, KeyId nodeId, KeyId tpId) {
37 super(networkId, nodeId);
38 this.tpId = tpId;
39 }
40
41 /**
Henry Yu4b4a7eb2016-11-09 20:07:53 -050042 * Creates an instance of termination point key based on a given
43 * network node key.
44 *
45 * @param nodeKey node key
46 * @param tpId termination point identifier
47 */
48 public TerminationPointKey(NetworkNodeKey nodeKey, KeyId tpId) {
49 super(nodeKey.networkId(), nodeKey.nodeId());
50 this.tpId = tpId;
51 }
52
53 /**
54 * Returns the termination point identifier.
55 *
56 * @return termination point identifier
57 */
58 public NetworkNodeKey networkNodeKey() {
59 return new NetworkNodeKey(networkId(), nodeId());
60 }
61
62 /**
63 * Returns the termination point identifier.
Aihua Guo1ce2dd12016-08-12 23:37:44 -040064 *
65 * @return termination point identifier
66 */
67 public KeyId tpId() {
68 return tpId;
69 }
70
71 @Override
72 public int hashCode() {
73 return Objects.hashCode(super.hashCode(), tpId);
74 }
75
76 @Override
77 public boolean equals(Object object) {
78 if (object instanceof TerminationPointKey) {
79 if (!super.equals(object)) {
80 return false;
81 }
82 TerminationPointKey that = (TerminationPointKey) object;
Henry Yu4b4a7eb2016-11-09 20:07:53 -050083 return Objects.equal(tpId, that.tpId);
Aihua Guo1ce2dd12016-08-12 23:37:44 -040084 }
85 return false;
86 }
87
88 @Override
89 public String toString() {
90 return toStringHelper(this)
91 .add("networkId", networkId())
92 .add("nodeId", nodeId())
93 .add("tpId", tpId)
94 .toString();
95 }
96
97}