Hyunsun Moon | 187bf53 | 2017-01-19 10:57:40 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | 80dff97 | 2017-08-03 22:46:30 -0700 | [diff] [blame^] | 2 | * Copyright 2017-present Open Networking Foundation |
Hyunsun Moon | 187bf53 | 2017-01-19 10:57:40 +0900 | [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.opencord.cordvtn.api.net; |
| 17 | |
| 18 | import com.google.common.base.MoreObjects; |
| 19 | import org.opencord.cordvtn.api.net.ServiceNetwork.DependencyType; |
| 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 Provider { |
| 29 | |
| 30 | private final ServiceNetwork provider; |
| 31 | private final DependencyType type; |
| 32 | |
| 33 | private Provider(ServiceNetwork provider, DependencyType type) { |
| 34 | this.provider = provider; |
| 35 | this.type = type; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Returns provider network. |
| 40 | * |
| 41 | * @return service network |
| 42 | */ |
| 43 | public ServiceNetwork provider() { |
| 44 | return provider; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Returns direct access type between subscriber and provider networks. |
| 49 | * |
| 50 | * @return type |
| 51 | */ |
| 52 | public DependencyType type() { |
| 53 | return type; |
| 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public boolean equals(Object obj) { |
| 58 | if (this == obj) { |
| 59 | return true; |
| 60 | } |
| 61 | |
| 62 | if (obj instanceof Provider) { |
| 63 | Provider that = (Provider) obj; |
| 64 | if (Objects.equals(provider, that.provider) && |
| 65 | Objects.equals(type, that.type)) { |
| 66 | return true; |
| 67 | } |
| 68 | } |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public int hashCode() { |
| 74 | return Objects.hash(provider, type); |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public String toString() { |
| 79 | return MoreObjects.toStringHelper(getClass()) |
| 80 | .add("provider", provider.id()) |
| 81 | .add("type", type) |
| 82 | .toString(); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * Returns new provider network builder instance. |
| 87 | * |
| 88 | * @return provider network |
| 89 | */ |
| 90 | public static Builder builder() { |
| 91 | return new Builder(); |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Builder of the provider network entities. |
| 96 | */ |
| 97 | public static final class Builder { |
| 98 | private ServiceNetwork provider; |
| 99 | private DependencyType type; |
| 100 | |
| 101 | private Builder() { |
| 102 | } |
| 103 | |
| 104 | /** |
| 105 | * Builds an immutable provider network. |
| 106 | * |
| 107 | * @return provider network instance |
| 108 | */ |
| 109 | public Provider build() { |
| 110 | checkNotNull(provider); |
| 111 | checkNotNull(type); |
| 112 | |
| 113 | return new Provider(provider, type); |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Returns provider network with the supplied provider. |
| 118 | * |
| 119 | * @param provider provider network |
| 120 | * @return provider network builder |
| 121 | */ |
| 122 | public Builder provider(ServiceNetwork provider) { |
| 123 | this.provider = provider; |
| 124 | return this; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Returns provider network with the supplied type. |
| 129 | * |
| 130 | * @param type type |
| 131 | * @return provider network builder |
| 132 | */ |
| 133 | public Builder type(DependencyType type) { |
| 134 | this.type = type; |
| 135 | return this; |
| 136 | } |
| 137 | } |
| 138 | } |