Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016 Open Networking Foundation |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [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.tetopology.management.api.node; |
| 17 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 18 | import com.google.common.base.Objects; |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 19 | import org.onosproject.tetopology.management.api.KeyId; |
| 20 | |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 21 | import static com.google.common.base.MoreObjects.toStringHelper; |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Representation of a termination point key or reference. |
| 25 | */ |
| 26 | public class TerminationPointKey extends NetworkNodeKey { |
| 27 | private final KeyId tpId; |
| 28 | |
| 29 | /** |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 30 | * Creates a termination point key. |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 31 | * |
| 32 | * @param networkId network identifier |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 33 | * @param nodeId node identifier |
| 34 | * @param tpId termination point identifier |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 35 | */ |
| 36 | public TerminationPointKey(KeyId networkId, KeyId nodeId, KeyId tpId) { |
| 37 | super(networkId, nodeId); |
| 38 | this.tpId = tpId; |
| 39 | } |
| 40 | |
| 41 | /** |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 42 | * 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 Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 64 | * |
| 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 Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 83 | return Objects.equal(tpId, that.tpId); |
Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [diff] [blame] | 84 | } |
| 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 | } |