Phaneendra Manda | efdf812 | 2015-10-26 18:39:13 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame^] | 2 | * Copyright 2015-present Open Networking Laboratory |
Phaneendra Manda | efdf812 | 2015-10-26 18:39:13 +0530 | [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.vtnrsc; |
| 17 | |
| 18 | import static com.google.common.base.MoreObjects.toStringHelper; |
| 19 | import static com.google.common.base.Preconditions.checkNotNull; |
| 20 | |
| 21 | import java.util.Objects; |
| 22 | |
| 23 | /** |
| 24 | * Implementation of port pair. |
| 25 | */ |
| 26 | public final class DefaultPortPair implements PortPair { |
| 27 | |
| 28 | private final PortPairId portPairId; |
| 29 | private final TenantId tenantId; |
| 30 | private final String name; |
| 31 | private final String description; |
| 32 | private final String ingress; |
| 33 | private final String egress; |
| 34 | |
| 35 | /** |
| 36 | * Default constructor to create Port Pair. |
| 37 | * |
| 38 | * @param portPairId port pair id |
| 39 | * @param tenantId tenant id |
| 40 | * @param name name of port pair |
| 41 | * @param description description of port pair |
| 42 | * @param ingress ingress port |
| 43 | * @param egress egress port |
| 44 | */ |
| 45 | private DefaultPortPair(PortPairId portPairId, TenantId tenantId, |
| 46 | String name, String description, |
| 47 | String ingress, String egress) { |
| 48 | |
| 49 | this.portPairId = portPairId; |
| 50 | this.tenantId = tenantId; |
| 51 | this.name = name; |
| 52 | this.description = description; |
| 53 | this.ingress = ingress; |
| 54 | this.egress = egress; |
| 55 | } |
| 56 | |
| 57 | @Override |
| 58 | public PortPairId portPairId() { |
| 59 | return portPairId; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public TenantId tenantId() { |
| 64 | return tenantId; |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public String name() { |
| 69 | return name; |
| 70 | } |
| 71 | |
| 72 | @Override |
| 73 | public String description() { |
| 74 | return description; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public String ingress() { |
| 79 | return ingress; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public String egress() { |
| 84 | return egress; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public int hashCode() { |
| 89 | return Objects.hash(portPairId, tenantId, name, description, |
| 90 | ingress, egress); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public boolean equals(Object obj) { |
| 95 | if (this == obj) { |
| 96 | return true; |
| 97 | } |
| 98 | if (obj instanceof DefaultPortPair) { |
| 99 | DefaultPortPair that = (DefaultPortPair) obj; |
| 100 | return Objects.equals(portPairId, that.portPairId) && |
| 101 | Objects.equals(tenantId, that.tenantId) && |
| 102 | Objects.equals(name, that.name) && |
| 103 | Objects.equals(description, that.description) && |
| 104 | Objects.equals(ingress, that.ingress) && |
| 105 | Objects.equals(egress, that.egress); |
| 106 | } |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | @Override |
| 111 | public boolean exactMatch(PortPair portPair) { |
| 112 | return this.equals(portPair) && |
| 113 | Objects.equals(this.portPairId, portPair.portPairId()) && |
| 114 | Objects.equals(this.tenantId, portPair.tenantId()); |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public String toString() { |
| 119 | return toStringHelper(this) |
| 120 | .add("id", portPairId.toString()) |
| 121 | .add("tenantId", tenantId.tenantId()) |
| 122 | .add("name", name) |
| 123 | .add("description", description) |
| 124 | .add("ingress", ingress) |
| 125 | .add("egress", egress) |
| 126 | .toString(); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * To create an instance of the builder. |
| 131 | * |
| 132 | * @return instance of builder |
| 133 | */ |
| 134 | public static Builder builder() { |
| 135 | return new Builder(); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Builder class for Port pair. |
| 140 | */ |
| 141 | public static final class Builder implements PortPair.Builder { |
| 142 | |
| 143 | private PortPairId portPairId; |
| 144 | private TenantId tenantId; |
| 145 | private String name; |
| 146 | private String description; |
| 147 | private String ingress; |
| 148 | private String egress; |
| 149 | |
| 150 | @Override |
| 151 | public Builder setId(PortPairId portPairId) { |
| 152 | this.portPairId = portPairId; |
| 153 | return this; |
| 154 | } |
| 155 | |
| 156 | @Override |
| 157 | public Builder setTenantId(TenantId tenantId) { |
| 158 | this.tenantId = tenantId; |
| 159 | return this; |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public Builder setName(String name) { |
| 164 | this.name = name; |
| 165 | return this; |
| 166 | } |
| 167 | |
| 168 | @Override |
| 169 | public Builder setDescription(String description) { |
| 170 | this.description = description; |
| 171 | return this; |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public Builder setIngress(String ingress) { |
| 176 | this.ingress = ingress; |
| 177 | return this; |
| 178 | } |
| 179 | |
| 180 | @Override |
| 181 | public Builder setEgress(String egress) { |
| 182 | this.egress = egress; |
| 183 | return this; |
| 184 | } |
| 185 | |
| 186 | @Override |
| 187 | public PortPair build() { |
| 188 | |
| 189 | checkNotNull(portPairId, "Port pair id cannot be null"); |
| 190 | checkNotNull(tenantId, "Tenant id cannot be null"); |
| 191 | checkNotNull(ingress, "Ingress of a port pair cannot be null"); |
| 192 | checkNotNull(egress, "Egress of a port pair cannot be null"); |
| 193 | |
| 194 | return new DefaultPortPair(portPairId, tenantId, name, description, |
| 195 | ingress, egress); |
| 196 | } |
| 197 | } |
| 198 | } |