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