Aihua Guo | 1ce2dd1 | 2016-08-12 23:37:44 -0400 | [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 java.util.List; |
| 19 | |
| 20 | import org.onosproject.tetopology.management.api.KeyId; |
| 21 | import org.onosproject.tetopology.management.api.node.TerminationPointKey; |
| 22 | |
| 23 | import com.google.common.base.MoreObjects; |
| 24 | import com.google.common.base.Objects; |
| 25 | |
| 26 | /** |
| 27 | * NetworkLink implementation. |
| 28 | * <p> |
| 29 | * The Set/Get methods below are defined to accept and pass references because |
| 30 | * the object class is treated as a "composite" object class that holds |
| 31 | * references to various member objects and their relationships, forming a |
| 32 | * data tree. Internal routines of the TE topology manager may use the |
| 33 | * following example methods to construct and manipulate any piece of data in |
| 34 | * the data tree: |
| 35 | *<pre> |
| 36 | * newNode.getTe().setAdminStatus(), or |
| 37 | * newNode.getSupportingNodeIds().add(nodeId), etc. |
| 38 | *</pre> |
| 39 | * Same for constructors where, for example, a child list may be constructed |
| 40 | * first and passed in by reference to its parent object constructor. |
| 41 | */ |
| 42 | public class DefaultNetworkLink implements NetworkLink { |
| 43 | private final KeyId linkId; |
| 44 | private TerminationPointKey source; |
| 45 | private TerminationPointKey destination; |
| 46 | private List<NetworkLinkKey> supportingLinkIds; |
| 47 | private TeLink te; |
| 48 | |
| 49 | /** |
| 50 | * Creates an instance of DefaultNetworkLink. |
| 51 | * |
| 52 | * @param linkId link identifier |
| 53 | */ |
| 54 | public DefaultNetworkLink(KeyId linkId) { |
| 55 | this.linkId = linkId; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Sets the link source point. |
| 60 | * |
| 61 | * @param source the source to set |
| 62 | */ |
| 63 | public void setSource(TerminationPointKey source) { |
| 64 | this.source = source; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Sets the link destination point. |
| 69 | * |
| 70 | * @param destination the destination to set |
| 71 | */ |
| 72 | public void setDestination(TerminationPointKey destination) { |
| 73 | this.destination = destination; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Sets the supporting link Ids. |
| 78 | * |
| 79 | * @param supportingLinkIds the supportingLinkIds to set |
| 80 | */ |
| 81 | public void setSupportingLinkIds(List<NetworkLinkKey> supportingLinkIds) { |
| 82 | this.supportingLinkIds = supportingLinkIds; |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Sets the te extension. |
| 87 | * |
| 88 | * @param te the te to set |
| 89 | */ |
| 90 | public void setTe(TeLink te) { |
| 91 | this.te = te; |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public KeyId linkId() { |
| 96 | return linkId; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public TerminationPointKey getSource() { |
| 101 | return source; |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public TerminationPointKey getDestination() { |
| 106 | return destination; |
| 107 | } |
| 108 | @Override |
| 109 | public List<NetworkLinkKey> getSupportingLinkIds() { |
| 110 | return supportingLinkIds; |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public TeLink getTe() { |
| 115 | return te; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public int hashCode() { |
| 120 | return Objects.hashCode(linkId, source, destination, supportingLinkIds, te); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public boolean equals(Object object) { |
| 125 | if (this == object) { |
| 126 | return true; |
| 127 | } |
| 128 | if (object instanceof DefaultNetworkLink) { |
| 129 | DefaultNetworkLink that = (DefaultNetworkLink) object; |
| 130 | return Objects.equal(this.linkId, that.linkId) && |
| 131 | Objects.equal(this.source, that.source) && |
| 132 | Objects.equal(this.destination, that.destination) && |
| 133 | Objects.equal(this.supportingLinkIds, that.supportingLinkIds) && |
| 134 | Objects.equal(this.te, that.te); |
| 135 | } |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | @Override |
| 140 | public String toString() { |
| 141 | return MoreObjects.toStringHelper(this) |
| 142 | .add("linkId", linkId) |
| 143 | .add("source", source) |
| 144 | .add("destination", destination) |
| 145 | .add("supportingLinkIds", supportingLinkIds) |
| 146 | .add("te", te) |
| 147 | .toString(); |
| 148 | } |
| 149 | |
| 150 | } |