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; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import com.google.common.base.Objects; |
| 20 | import com.google.common.collect.ImmutableMap; |
| 21 | import com.google.common.collect.Maps; |
| 22 | import org.onosproject.net.DeviceId; |
| 23 | import org.onosproject.tetopology.management.api.link.TeLink; |
| 24 | import org.onosproject.tetopology.management.api.link.TeLinkTpKey; |
| 25 | import org.onosproject.tetopology.management.api.node.TeNode; |
| 26 | |
| 27 | import java.util.BitSet; |
| 28 | import java.util.Map; |
| 29 | |
| 30 | /** |
| 31 | * Default implementation of TeTopology. |
| 32 | */ |
| 33 | public class DefaultTeTopology implements TeTopology { |
| 34 | private final TeTopologyKey teKey; |
| 35 | private final Map<Long, TeNode> teNodes; |
| 36 | private final Map<TeLinkTpKey, TeLink> teLinks; |
| 37 | private final String idString; |
| 38 | private final CommonTopologyData common; |
| 39 | |
| 40 | /** |
| 41 | * Creates an instance of DefaultTeTopology. |
| 42 | * |
| 43 | * @param teKey the TE topology key used for searching |
| 44 | * @param teNodes the list of TE nodes in the topology |
| 45 | * @param teLinks the list of TE links in the topology |
| 46 | * @param idString the TE Topology id string value |
| 47 | * @param common the common topology attributes |
| 48 | */ |
| 49 | public DefaultTeTopology(TeTopologyKey teKey, Map<Long, TeNode> teNodes, |
| 50 | Map<TeLinkTpKey, TeLink> teLinks, String idString, |
| 51 | CommonTopologyData common) { |
| 52 | this.teKey = teKey; |
| 53 | this.teNodes = teNodes != null ? Maps.newHashMap(teNodes) : null; |
| 54 | this.teLinks = teLinks != null ? Maps.newHashMap(teLinks) : null; |
| 55 | this.idString = idString; |
| 56 | this.common = common; |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public TeTopologyKey teTopologyId() { |
| 61 | return teKey; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public BitSet flags() { |
| 66 | if (common == null) { |
| 67 | return null; |
| 68 | } |
| 69 | return common.flags(); |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public OptimizationType optimization() { |
| 74 | if (common == null) { |
| 75 | return null; |
| 76 | } |
| 77 | return common.optimization(); |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public Map<Long, TeNode> teNodes() { |
| 82 | if (teNodes == null) { |
| 83 | return null; |
| 84 | } |
| 85 | return ImmutableMap.copyOf(teNodes); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public TeNode teNode(long teNodeId) { |
| 90 | return teNodes.get(teNodeId); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public Map<TeLinkTpKey, TeLink> teLinks() { |
| 95 | if (teLinks == null) { |
| 96 | return null; |
| 97 | } |
| 98 | return ImmutableMap.copyOf(teLinks); |
| 99 | } |
| 100 | |
| 101 | @Override |
| 102 | public TeLink teLink(TeLinkTpKey teLinkId) { |
| 103 | return teLinks.get(teLinkId); |
| 104 | } |
| 105 | |
| 106 | @Override |
| 107 | public String teTopologyIdStringValue() { |
| 108 | return idString; |
| 109 | } |
| 110 | |
| 111 | @Override |
| 112 | public KeyId networkId() { |
| 113 | if (common == null) { |
| 114 | return null; |
| 115 | } |
| 116 | return common.networkId(); |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public DeviceId ownerId() { |
| 121 | if (common == null) { |
| 122 | return null; |
| 123 | } |
| 124 | return common.ownerId(); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public int hashCode() { |
| 129 | return Objects.hashCode(teKey, teNodes, |
| 130 | teLinks, common, idString); |
| 131 | } |
| 132 | |
| 133 | @Override |
| 134 | public boolean equals(Object object) { |
| 135 | if (this == object) { |
| 136 | return true; |
| 137 | } |
| 138 | if (object instanceof DefaultTeTopology) { |
| 139 | DefaultTeTopology that = (DefaultTeTopology) object; |
| 140 | return Objects.equal(teKey, that.teKey) && |
| 141 | Objects.equal(teNodes, that.teNodes) && |
| 142 | Objects.equal(teLinks, that.teLinks) && |
| 143 | Objects.equal(common, that.common) && |
| 144 | Objects.equal(idString, that.idString); |
| 145 | } |
| 146 | return false; |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | public String toString() { |
| 151 | return MoreObjects.toStringHelper(this) |
| 152 | .add("teKey", teKey) |
| 153 | .add("teNodes", teNodes) |
| 154 | .add("teLinks", teLinks) |
| 155 | .add("common", common) |
| 156 | .add("idString", idString) |
| 157 | .toString(); |
| 158 | } |
| 159 | |
| 160 | } |