Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016 Open Networking Foundation |
Henry Yu | 4b4a7eb | 2016-11-09 20:07:53 -0500 | [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 | |
| 18 | import org.onosproject.tetopology.management.api.TeTopologyKey; |
| 19 | |
| 20 | import com.google.common.base.MoreObjects.ToStringHelper; |
| 21 | import com.google.common.base.Objects; |
| 22 | |
| 23 | /** |
| 24 | * TE node Key. |
| 25 | */ |
| 26 | public class TeNodeKey extends TeTopologyKey { |
| 27 | private final long teNodeId; |
| 28 | |
| 29 | /** |
| 30 | * Creates a TE node key. |
| 31 | * |
| 32 | * @param providerId provider identifier |
| 33 | * @param clientId client identifier |
| 34 | * @param topologyId topology identifier |
| 35 | * @param teNodeId TE node identifier |
| 36 | */ |
| 37 | public TeNodeKey(long providerId, long clientId, |
| 38 | long topologyId, long teNodeId) { |
| 39 | super(providerId, clientId, topologyId); |
| 40 | this.teNodeId = teNodeId; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Creates a TE node key based on a given TE topology key and a |
| 45 | * TE node identifier. |
| 46 | * |
| 47 | * @param teTopologyKey the key of TE Topology to which this node belongs |
| 48 | * @param nodeId TE node identifier |
| 49 | */ |
| 50 | public TeNodeKey(TeTopologyKey teTopologyKey, long nodeId) { |
| 51 | super(teTopologyKey.providerId(), teTopologyKey.clientId(), |
| 52 | teTopologyKey.topologyId()); |
| 53 | this.teNodeId = nodeId; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns the TE Node identifier. |
| 58 | * |
| 59 | * @return the TE node id |
| 60 | */ |
| 61 | public long teNodeId() { |
| 62 | return teNodeId; |
| 63 | } |
| 64 | |
| 65 | public TeTopologyKey teTopologyKey() { |
| 66 | return new TeTopologyKey(providerId(), clientId(), topologyId()); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public int hashCode() { |
| 71 | return Objects.hashCode(super.hashCode(), teNodeId); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public boolean equals(Object object) { |
| 76 | if (this == object) { |
| 77 | return true; |
| 78 | } |
| 79 | if (object instanceof TeNodeKey) { |
| 80 | if (!super.equals(object)) { |
| 81 | return false; |
| 82 | } |
| 83 | TeNodeKey that = (TeNodeKey) object; |
| 84 | return Objects.equal(this.teNodeId, that.teNodeId); |
| 85 | } |
| 86 | return false; |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Returns ToStringHelper with an additional TE node identifier. |
| 91 | * |
| 92 | * @return toStringHelper |
| 93 | */ |
| 94 | protected ToStringHelper toTeNodeKeyStringHelper() { |
| 95 | return toTopologyKeyStringHelper().add("teNodeId", teNodeId); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public String toString() { |
| 100 | return toTeNodeKeyStringHelper().toString(); |
| 101 | } |
| 102 | } |