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 | |
| 22 | import java.util.HashMap; |
| 23 | import java.util.Map; |
| 24 | |
| 25 | /** |
| 26 | * Default TeTopologies implementation. |
| 27 | */ |
| 28 | public class DefaultTeTopologies implements TeTopologies { |
| 29 | private final String name; |
| 30 | private final Map<TeTopologyKey, TeTopology> teTopologies; |
| 31 | |
| 32 | /** |
| 33 | * Creates an instance of DefaultTeTopologies. |
| 34 | * |
| 35 | * @param name the name of a TeTopology set |
| 36 | * @param teTopologies the list of TeTopology |
| 37 | */ |
| 38 | public DefaultTeTopologies(String name, Map<TeTopologyKey, TeTopology> teTopologies) { |
| 39 | this.name = name; |
| 40 | this.teTopologies = teTopologies != null ? |
| 41 | new HashMap<>(teTopologies) : null; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public String name() { |
| 46 | return name; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public Map<TeTopologyKey, TeTopology> teTopologies() { |
| 51 | if (teTopologies == null) { |
| 52 | return null; |
| 53 | } |
| 54 | return ImmutableMap.copyOf(teTopologies); |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public int hashCode() { |
| 59 | return Objects.hashCode(name, teTopologies); |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public boolean equals(Object object) { |
| 64 | if (this == object) { |
| 65 | return true; |
| 66 | } |
| 67 | if (object instanceof DefaultTeTopologies) { |
| 68 | DefaultTeTopologies that = (DefaultTeTopologies) object; |
| 69 | return Objects.equal(name, that.name) && |
| 70 | Objects.equal(teTopologies, that.teTopologies); |
| 71 | } |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public String toString() { |
| 77 | return MoreObjects.toStringHelper(this) |
| 78 | .add("name", name) |
| 79 | .add("teTopologies", teTopologies) |
| 80 | .toString(); |
| 81 | } |
| 82 | } |