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.link; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.base.Objects; |
| 20 | import com.google.common.collect.ImmutableList; |
| 21 | import com.google.common.collect.Lists; |
| 22 | import org.onosproject.tetopology.management.api.KeyId; |
| 23 | import org.onosproject.tetopology.management.api.node.NodeTpKey; |
| 24 | |
| 25 | import java.util.List; |
| 26 | |
| 27 | /** |
| 28 | * Default implementation of a network link. |
| 29 | */ |
| 30 | public class DefaultNetworkLink implements NetworkLink { |
| 31 | private final KeyId linkId; |
| 32 | private final NodeTpKey source; |
| 33 | private final NodeTpKey destination; |
| 34 | private final List<NetworkLinkKey> supportingLinkIds; |
| 35 | private final TeLink teLink; |
| 36 | |
| 37 | /** |
| 38 | * Creates an instance of a network link. |
| 39 | * |
| 40 | * @param linkId link identifier |
| 41 | * @param source source of termination point |
| 42 | * @param destination destination termination point |
| 43 | * @param supportingLinkIds supporting links |
| 44 | * @param teLink TE link which this network link maps to |
| 45 | */ |
| 46 | public DefaultNetworkLink(KeyId linkId, |
| 47 | NodeTpKey source, |
| 48 | NodeTpKey destination, |
| 49 | List<NetworkLinkKey> supportingLinkIds, |
| 50 | TeLink teLink) { |
| 51 | this.linkId = linkId; |
| 52 | this.source = source; |
| 53 | this.destination = destination; |
| 54 | this.supportingLinkIds = supportingLinkIds != null ? |
| 55 | Lists.newArrayList(supportingLinkIds) : null; |
| 56 | this.teLink = teLink; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public KeyId linkId() { |
| 61 | return linkId; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public NodeTpKey source() { |
| 66 | return source; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public NodeTpKey destination() { |
| 71 | return destination; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public List<NetworkLinkKey> supportingLinkIds() { |
| 76 | if (supportingLinkIds == null) { |
| 77 | return null; |
| 78 | } |
| 79 | return ImmutableList.copyOf(supportingLinkIds); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public TeLink teLink() { |
| 84 | return teLink; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public int hashCode() { |
| 89 | return Objects.hashCode(linkId, source, destination, |
| 90 | supportingLinkIds, teLink); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public boolean equals(Object object) { |
| 95 | if (this == object) { |
| 96 | return true; |
| 97 | } |
| 98 | if (object instanceof DefaultNetworkLink) { |
| 99 | DefaultNetworkLink that = (DefaultNetworkLink) object; |
| 100 | return Objects.equal(linkId, that.linkId) && |
| 101 | Objects.equal(source, that.source) && |
| 102 | Objects.equal(destination, that.destination) && |
| 103 | Objects.equal(supportingLinkIds, that.supportingLinkIds) && |
| 104 | Objects.equal(teLink, that.teLink); |
| 105 | } |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | @Override |
| 110 | public String toString() { |
| 111 | return MoreObjects.toStringHelper(this) |
| 112 | .add("linkId", linkId) |
| 113 | .add("source", source) |
| 114 | .add("destination", destination) |
| 115 | .add("supportingLinkIds", supportingLinkIds) |
| 116 | .add("teLink", teLink) |
| 117 | .toString(); |
| 118 | } |
| 119 | |
| 120 | } |