Hyunsun Moon | eaf75e6 | 2016-09-27 16:40:23 -0700 | [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.opencord.cordvtn.api; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.opencord.cordvtn.api.Dependency.Type; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | import static com.google.common.base.Preconditions.checkNotNull; |
| 24 | |
| 25 | /** |
| 26 | * Representation of a provider network. |
| 27 | */ |
| 28 | public final class ProviderNetwork { |
| 29 | |
| 30 | private final NetworkId id; |
| 31 | private final Type type; |
| 32 | |
| 33 | private ProviderNetwork(NetworkId id, Type type) { |
| 34 | this.id = id; |
| 35 | this.type = type; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Returns network id. |
| 40 | * |
| 41 | * @return network id |
| 42 | */ |
| 43 | public NetworkId id() { |
| 44 | return id; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns the direct access type with this provider network. |
| 49 | * |
| 50 | * @return direct access type |
| 51 | */ |
| 52 | public Type type() { |
| 53 | return type; |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Returns immutable provider network with the supplied network id and type. |
| 58 | * |
| 59 | * @param id network id |
| 60 | * @param type direct access type |
| 61 | * @return provider network |
| 62 | */ |
| 63 | public static ProviderNetwork of(NetworkId id, Type type) { |
| 64 | checkNotNull(id); |
| 65 | checkNotNull(type); |
| 66 | return new ProviderNetwork(id, type); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public boolean equals(Object obj) { |
| 71 | if (this == obj) { |
| 72 | return true; |
| 73 | } |
| 74 | |
| 75 | if (obj instanceof ProviderNetwork) { |
| 76 | ProviderNetwork that = (ProviderNetwork) obj; |
| 77 | if (Objects.equals(id, that.id) && |
| 78 | Objects.equals(type, that.type)) { |
| 79 | return true; |
| 80 | } |
| 81 | } |
| 82 | return false; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public int hashCode() { |
| 87 | return Objects.hash(id, type); |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public String toString() { |
| 92 | return MoreObjects.toStringHelper(getClass()) |
| 93 | .add("id", id) |
| 94 | .add("type", type) |
| 95 | .toString(); |
| 96 | } |
| 97 | } |