| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.vcloud.domain.network.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | import java.util.List; |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import org.jclouds.javax.annotation.Nullable; |
| 28 | |
| 29 | import org.jclouds.vcloud.domain.ReferenceType; |
| 30 | import org.jclouds.vcloud.domain.Task; |
| 31 | import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl; |
| 32 | import org.jclouds.vcloud.domain.network.Features; |
| 33 | import org.jclouds.vcloud.domain.network.FenceMode; |
| 34 | import org.jclouds.vcloud.domain.network.IpScope; |
| 35 | import org.jclouds.vcloud.domain.network.OrgNetwork; |
| 36 | |
| 37 | import com.google.common.collect.Iterables; |
| 38 | import com.google.common.collect.Lists; |
| 39 | import com.google.common.collect.Sets; |
| 40 | |
| 41 | /** |
| 42 | * |
| 43 | * @author Adrian Cole |
| 44 | */ |
| 45 | public class OrgNetworkImpl extends ReferenceTypeImpl implements OrgNetwork { |
| 46 | @Nullable |
| 47 | private final ReferenceType org; |
| 48 | @Nullable |
| 49 | private final String description; |
| 50 | private final List<Task> tasks = Lists.newArrayList(); |
| 51 | private final Configuration configuration; |
| 52 | @Nullable |
| 53 | private final ReferenceType networkPool; |
| 54 | private final Set<String> allowedExternalIpAddresses = Sets.newLinkedHashSet(); |
| 55 | |
| 56 | public OrgNetworkImpl(String name, String type, URI id, @Nullable ReferenceType org, @Nullable String description, |
| 57 | Iterable<Task> tasks, Configuration configuration, @Nullable ReferenceType networkPool, |
| 58 | Iterable<String> allowedExternalIpAddresses) { |
| 59 | super(name, type, id); |
| 60 | this.org = org; |
| 61 | this.description = description; |
| 62 | Iterables.addAll(this.tasks, checkNotNull(tasks, "tasks")); |
| 63 | this.configuration = checkNotNull(configuration, "configuration"); |
| 64 | this.networkPool = networkPool; |
| 65 | Iterables.addAll(this.allowedExternalIpAddresses, checkNotNull(allowedExternalIpAddresses, |
| 66 | "allowedExternalIpAddresses")); |
| 67 | } |
| 68 | |
| 69 | public static class ConfigurationImpl implements Configuration { |
| 70 | |
| 71 | @Nullable |
| 72 | private final IpScope ipScope; |
| 73 | @Nullable |
| 74 | private final ReferenceType parentNetwork; |
| 75 | private final FenceMode fenceMode; |
| 76 | private final Features features; |
| 77 | |
| 78 | public ConfigurationImpl(@Nullable IpScope ipScope, @Nullable ReferenceType parentNetwork, FenceMode fenceMode, |
| 79 | @Nullable Features features) { |
| 80 | this.ipScope = ipScope; |
| 81 | this.parentNetwork = parentNetwork; |
| 82 | this.fenceMode = checkNotNull(fenceMode, "fenceMode"); |
| 83 | this.features = features; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * {@inheritDoc} |
| 88 | */ |
| 89 | @Override |
| 90 | public IpScope getIpScope() { |
| 91 | return ipScope; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * {@inheritDoc} |
| 96 | */ |
| 97 | @Override |
| 98 | public ReferenceType getParentNetwork() { |
| 99 | return parentNetwork; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * {@inheritDoc} |
| 104 | */ |
| 105 | @Override |
| 106 | public FenceMode getFenceMode() { |
| 107 | return fenceMode; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * {@inheritDoc} |
| 112 | */ |
| 113 | @Override |
| 114 | @Nullable |
| 115 | public Features getFeatures() { |
| 116 | return features; |
| 117 | } |
| 118 | |
| 119 | @Override |
| 120 | public int hashCode() { |
| 121 | final int prime = 31; |
| 122 | int result = 1; |
| 123 | result = prime * result + ((features == null) ? 0 : features.hashCode()); |
| 124 | result = prime * result + ((fenceMode == null) ? 0 : fenceMode.hashCode()); |
| 125 | result = prime * result + ((ipScope == null) ? 0 : ipScope.hashCode()); |
| 126 | result = prime * result + ((parentNetwork == null) ? 0 : parentNetwork.hashCode()); |
| 127 | return result; |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public boolean equals(Object obj) { |
| 132 | if (this == obj) |
| 133 | return true; |
| 134 | if (obj == null) |
| 135 | return false; |
| 136 | if (getClass() != obj.getClass()) |
| 137 | return false; |
| 138 | ConfigurationImpl other = (ConfigurationImpl) obj; |
| 139 | if (features == null) { |
| 140 | if (other.features != null) |
| 141 | return false; |
| 142 | } else if (!features.equals(other.features)) |
| 143 | return false; |
| 144 | if (fenceMode == null) { |
| 145 | if (other.fenceMode != null) |
| 146 | return false; |
| 147 | } else if (!fenceMode.equals(other.fenceMode)) |
| 148 | return false; |
| 149 | if (ipScope == null) { |
| 150 | if (other.ipScope != null) |
| 151 | return false; |
| 152 | } else if (!ipScope.equals(other.ipScope)) |
| 153 | return false; |
| 154 | if (parentNetwork == null) { |
| 155 | if (other.parentNetwork != null) |
| 156 | return false; |
| 157 | } else if (!parentNetwork.equals(other.parentNetwork)) |
| 158 | return false; |
| 159 | return true; |
| 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public String toString() { |
| 164 | return "[features=" + features + ", fenceMode=" + fenceMode + ", ipScope=" + ipScope + ", parentNetwork=" |
| 165 | + parentNetwork + "]"; |
| 166 | } |
| 167 | |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * {@inheritDoc} |
| 172 | */ |
| 173 | @Override |
| 174 | public ReferenceType getOrg() { |
| 175 | return org; |
| 176 | } |
| 177 | |
| 178 | /** |
| 179 | * {@inheritDoc} |
| 180 | */ |
| 181 | @Override |
| 182 | public String getDescription() { |
| 183 | return description; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * {@inheritDoc} |
| 188 | */ |
| 189 | @Override |
| 190 | public List<Task> getTasks() { |
| 191 | return tasks; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * {@inheritDoc} |
| 196 | */ |
| 197 | @Override |
| 198 | public Configuration getConfiguration() { |
| 199 | return configuration; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * {@inheritDoc} |
| 204 | */ |
| 205 | @Override |
| 206 | public ReferenceType getNetworkPool() { |
| 207 | return networkPool; |
| 208 | } |
| 209 | |
| 210 | /** |
| 211 | * {@inheritDoc} |
| 212 | */ |
| 213 | @Override |
| 214 | public Set<String> getAllowedExternalIpAddresses() { |
| 215 | return allowedExternalIpAddresses; |
| 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public int hashCode() { |
| 220 | final int prime = 31; |
| 221 | int result = super.hashCode(); |
| 222 | result = prime * result + ((allowedExternalIpAddresses == null) ? 0 : allowedExternalIpAddresses.hashCode()); |
| 223 | result = prime * result + ((configuration == null) ? 0 : configuration.hashCode()); |
| 224 | result = prime * result + ((description == null) ? 0 : description.hashCode()); |
| 225 | result = prime * result + ((networkPool == null) ? 0 : networkPool.hashCode()); |
| 226 | result = prime * result + ((org == null) ? 0 : org.hashCode()); |
| 227 | result = prime * result + ((tasks == null) ? 0 : tasks.hashCode()); |
| 228 | return result; |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public boolean equals(Object obj) { |
| 233 | if (this == obj) |
| 234 | return true; |
| 235 | if (!super.equals(obj)) |
| 236 | return false; |
| 237 | if (getClass() != obj.getClass()) |
| 238 | return false; |
| 239 | OrgNetworkImpl other = (OrgNetworkImpl) obj; |
| 240 | if (allowedExternalIpAddresses == null) { |
| 241 | if (other.allowedExternalIpAddresses != null) |
| 242 | return false; |
| 243 | } else if (!allowedExternalIpAddresses.equals(other.allowedExternalIpAddresses)) |
| 244 | return false; |
| 245 | if (configuration == null) { |
| 246 | if (other.configuration != null) |
| 247 | return false; |
| 248 | } else if (!configuration.equals(other.configuration)) |
| 249 | return false; |
| 250 | if (description == null) { |
| 251 | if (other.description != null) |
| 252 | return false; |
| 253 | } else if (!description.equals(other.description)) |
| 254 | return false; |
| 255 | if (networkPool == null) { |
| 256 | if (other.networkPool != null) |
| 257 | return false; |
| 258 | } else if (!networkPool.equals(other.networkPool)) |
| 259 | return false; |
| 260 | if (org == null) { |
| 261 | if (other.org != null) |
| 262 | return false; |
| 263 | } else if (!org.equals(other.org)) |
| 264 | return false; |
| 265 | if (tasks == null) { |
| 266 | if (other.tasks != null) |
| 267 | return false; |
| 268 | } else if (!tasks.equals(other.tasks)) |
| 269 | return false; |
| 270 | return true; |
| 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public String toString() { |
| 275 | return "[allowedExternalIpAddresses=" + allowedExternalIpAddresses + ", configuration=" + configuration |
| 276 | + ", description=" + description + ", networkPool=" + networkPool + ", org=" + org + ", tasks=" + tasks |
| 277 | + "]"; |
| 278 | } |
| 279 | |
| 280 | } |