Yixiao Chen | 68bfab2 | 2016-11-11 11:04:10 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-present 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.impl; |
| 17 | |
| 18 | import java.util.List; |
| 19 | import java.util.Map; |
| 20 | |
| 21 | import org.apache.commons.collections.MapUtils; |
| 22 | import org.onosproject.tetopology.management.api.KeyId; |
| 23 | import org.onosproject.tetopology.management.api.node.NetworkNode; |
| 24 | import org.onosproject.tetopology.management.api.node.NetworkNodeKey; |
| 25 | import org.onosproject.tetopology.management.api.node.TeNodeKey; |
| 26 | import org.onosproject.tetopology.management.api.node.TerminationPoint; |
| 27 | |
| 28 | import com.google.common.base.MoreObjects; |
| 29 | import com.google.common.base.Objects; |
| 30 | import com.google.common.collect.ImmutableList; |
| 31 | import com.google.common.collect.Lists; |
| 32 | |
| 33 | /** |
| 34 | * Network Node representation in store. |
| 35 | */ |
| 36 | public class InternalNetworkNode { |
| 37 | private List<NetworkNodeKey> supportingNodeIds; |
| 38 | private List<KeyId> tpIds; |
| 39 | private TeNodeKey teNodeKey; |
| 40 | private boolean parentUpdate; |
| 41 | private boolean childUpdate; |
| 42 | |
| 43 | /** |
| 44 | * Creates an instance of InternalNetworkNode. |
| 45 | * |
| 46 | * @param node the network node |
| 47 | * @param parentUpdate the flag if the data is updated by parent |
| 48 | */ |
| 49 | public InternalNetworkNode(NetworkNode node, boolean parentUpdate) { |
| 50 | supportingNodeIds = node |
| 51 | .supportingNodeIds() == null ? null |
| 52 | : Lists.newArrayList(node |
| 53 | .supportingNodeIds()); |
| 54 | if (MapUtils.isNotEmpty(node.terminationPoints())) { |
| 55 | tpIds = Lists.newArrayList(); |
| 56 | for (Map.Entry<KeyId, TerminationPoint> entry : node |
| 57 | .terminationPoints().entrySet()) { |
| 58 | tpIds.add(entry.getKey()); |
| 59 | } |
| 60 | } |
| 61 | this.parentUpdate = parentUpdate; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Returns the list of supporting node Ids. |
| 66 | * |
| 67 | * @return the supporting nodeIds |
| 68 | */ |
| 69 | public List<NetworkNodeKey> supportingNodeIds() { |
| 70 | return supportingNodeIds == null ? null |
| 71 | : ImmutableList |
| 72 | .copyOf(supportingNodeIds); |
| 73 | } |
| 74 | |
| 75 | /** |
| 76 | * Sets the list of supporting node Ids. |
| 77 | * |
| 78 | * @param supportingNodeIds the supportingNodeIds to set |
| 79 | */ |
| 80 | public void setSupportingNodeIds(List<NetworkNodeKey> supportingNodeIds) { |
| 81 | this.supportingNodeIds = supportingNodeIds == null ? null |
| 82 | : Lists.newArrayList(supportingNodeIds); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns the list of termination point Ids. |
| 87 | * |
| 88 | * @return the termination point Ids |
| 89 | */ |
| 90 | public List<KeyId> tpIds() { |
| 91 | return tpIds; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Sets the list of termination point Ids. |
| 96 | * |
| 97 | * @param tpIds the tpIds to set |
| 98 | */ |
| 99 | public void setTpIds(List<KeyId> tpIds) { |
| 100 | this.tpIds = tpIds; |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Returns the TE Node key. |
| 105 | * |
| 106 | * @return the teNodeKey |
| 107 | */ |
| 108 | public TeNodeKey teNodeKey() { |
| 109 | return teNodeKey; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Sets the TE Node key. |
| 114 | * |
| 115 | * @param teNodeKey the teNodeKey to set |
| 116 | */ |
| 117 | public void setTeNodeKey(TeNodeKey teNodeKey) { |
| 118 | this.teNodeKey = teNodeKey; |
| 119 | } |
| 120 | |
| 121 | /** |
| 122 | * Returns the flag if the data was updated by parent change. |
| 123 | * |
| 124 | * @return value of parentUpdate |
| 125 | */ |
| 126 | public boolean parentUpdate() { |
| 127 | return parentUpdate; |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Returns the flag if the data was updated by child change. |
| 132 | * |
| 133 | * @return value of childUpdate |
| 134 | */ |
| 135 | public boolean childUpdate() { |
| 136 | return childUpdate; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Sets the flag if the data was updated by child change. |
| 141 | * |
| 142 | * @param childUpdate the childUpdate value to set |
| 143 | */ |
| 144 | public void setChildUpdate(boolean childUpdate) { |
| 145 | this.childUpdate = childUpdate; |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public int hashCode() { |
| 150 | return Objects.hashCode(supportingNodeIds, tpIds, teNodeKey); |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public boolean equals(Object object) { |
| 155 | if (this == object) { |
| 156 | return true; |
| 157 | } |
| 158 | if (object instanceof InternalNetworkNode) { |
| 159 | InternalNetworkNode that = (InternalNetworkNode) object; |
| 160 | return Objects.equal(supportingNodeIds, that.supportingNodeIds) |
| 161 | && Objects.equal(tpIds, that.tpIds) |
| 162 | && Objects.equal(teNodeKey, that.teNodeKey); |
| 163 | } |
| 164 | return false; |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public String toString() { |
| 169 | return MoreObjects.toStringHelper(this) |
| 170 | .add("supportingNodeIds", supportingNodeIds) |
| 171 | .add("tpIds", tpIds) |
| 172 | .add("teNodeKey", teNodeKey) |
| 173 | .add("parentUpdate", parentUpdate) |
| 174 | .add("childUpdate", childUpdate) |
| 175 | .toString(); |
| 176 | } |
| 177 | } |