| 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.trmk.vcloud_0_8.domain.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | import java.util.HashSet; |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import org.jclouds.cim.ResourceAllocationSettingData; |
| 28 | import org.jclouds.cim.VirtualSystemSettingData; |
| 29 | import org.jclouds.trmk.vcloud_0_8.TerremarkVCloudMediaType; |
| 30 | import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType; |
| 31 | import org.jclouds.trmk.vcloud_0_8.domain.Status; |
| 32 | import org.jclouds.trmk.vcloud_0_8.domain.VApp; |
| 33 | |
| 34 | import com.google.common.collect.ListMultimap; |
| 35 | |
| 36 | /** |
| 37 | * |
| 38 | * @author Adrian Cole |
| 39 | * |
| 40 | */ |
| 41 | public class VAppImpl implements VApp { |
| 42 | private final String name; |
| 43 | private final URI href; |
| 44 | private final ReferenceType vDC; |
| 45 | private final Set<ReferenceType> extendedInfo; |
| 46 | private final Status status; |
| 47 | private final Long size; |
| 48 | private final ListMultimap<String, String> networkToAddresses; |
| 49 | private final String operatingSystemDescription; |
| 50 | private final VirtualSystemSettingData system; |
| 51 | private final Set<ResourceAllocationSettingData> resourceAllocations; |
| 52 | private final Integer osType; |
| 53 | |
| 54 | public VAppImpl(String name, URI href, Status status, Long size, ReferenceType vDC, |
| 55 | ListMultimap<String, String> networkToAddresses, Integer osType, String operatingSystemDescription, |
| 56 | VirtualSystemSettingData system, Set<ResourceAllocationSettingData> resourceAllocations) { |
| 57 | this(name, href, status, size, vDC, networkToAddresses, osType, operatingSystemDescription, system, |
| 58 | resourceAllocations, new HashSet<ReferenceType>()); |
| 59 | } |
| 60 | |
| 61 | public VAppImpl(String name, URI href, Status status, Long size, ReferenceType vDC, |
| 62 | ListMultimap<String, String> networkToAddresses, Integer osType, String operatingSystemDescription, |
| 63 | VirtualSystemSettingData system, Set<ResourceAllocationSettingData> resourceAllocations, |
| 64 | Set<ReferenceType> extendedInfo) { |
| 65 | this.name = checkNotNull(name, "name"); |
| 66 | this.href = checkNotNull(href, "href"); |
| 67 | this.status = checkNotNull(status, "status"); |
| 68 | this.size = size; |
| 69 | this.vDC = vDC; |
| 70 | this.networkToAddresses = checkNotNull(networkToAddresses, "networkToAddresses"); |
| 71 | this.osType = osType; |
| 72 | this.operatingSystemDescription = operatingSystemDescription; |
| 73 | this.system = system; |
| 74 | this.resourceAllocations = checkNotNull(resourceAllocations, "resourceAllocations"); |
| 75 | this.extendedInfo = extendedInfo; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public Status getStatus() { |
| 80 | return status; |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public ListMultimap<String, String> getNetworkToAddresses() { |
| 85 | return networkToAddresses; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public Integer getOsType() { |
| 90 | return osType; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public String getOperatingSystemDescription() { |
| 95 | return operatingSystemDescription; |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public VirtualSystemSettingData getSystem() { |
| 100 | return system; |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public Set<ResourceAllocationSettingData> getResourceAllocations() { |
| 105 | return resourceAllocations; |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public ReferenceType getVDC() { |
| 110 | return vDC; |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public Set<ReferenceType> getExtendedInfo() { |
| 115 | return extendedInfo; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public int hashCode() { |
| 120 | final int prime = 31; |
| 121 | int result = 1; |
| 122 | result = prime * result + ((href == null) ? 0 : href.hashCode()); |
| 123 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 124 | result = prime * result + ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode()); |
| 125 | result = prime * result + ((operatingSystemDescription == null) ? 0 : operatingSystemDescription.hashCode()); |
| 126 | result = prime * result + ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode()); |
| 127 | result = prime * result + ((size == null) ? 0 : size.hashCode()); |
| 128 | result = prime * result + ((osType == null) ? 0 : osType.hashCode()); |
| 129 | result = prime * result + ((status == null) ? 0 : status.hashCode()); |
| 130 | result = prime * result + ((system == null) ? 0 : system.hashCode()); |
| 131 | result = prime * result + ((vDC == null) ? 0 : vDC.hashCode()); |
| 132 | result = prime * result + ((extendedInfo == null) ? 0 : extendedInfo.hashCode()); |
| 133 | return result; |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public boolean equals(Object obj) { |
| 138 | if (this == obj) |
| 139 | return true; |
| 140 | if (obj == null) |
| 141 | return false; |
| 142 | if (getClass() != obj.getClass()) |
| 143 | return false; |
| 144 | VAppImpl other = (VAppImpl) obj; |
| 145 | if (href == null) { |
| 146 | if (other.href != null) |
| 147 | return false; |
| 148 | } else if (!href.equals(other.href)) |
| 149 | return false; |
| 150 | if (name == null) { |
| 151 | if (other.name != null) |
| 152 | return false; |
| 153 | } else if (!name.equals(other.name)) |
| 154 | return false; |
| 155 | if (osType == null) { |
| 156 | if (other.osType != null) |
| 157 | return false; |
| 158 | } else if (!osType.equals(other.osType)) |
| 159 | return false; |
| 160 | if (networkToAddresses == null) { |
| 161 | if (other.networkToAddresses != null) |
| 162 | return false; |
| 163 | } else if (!networkToAddresses.equals(other.networkToAddresses)) |
| 164 | return false; |
| 165 | if (operatingSystemDescription == null) { |
| 166 | if (other.operatingSystemDescription != null) |
| 167 | return false; |
| 168 | } else if (!operatingSystemDescription.equals(other.operatingSystemDescription)) |
| 169 | return false; |
| 170 | if (resourceAllocations == null) { |
| 171 | if (other.resourceAllocations != null) |
| 172 | return false; |
| 173 | } else if (!resourceAllocations.equals(other.resourceAllocations)) |
| 174 | return false; |
| 175 | if (size == null) { |
| 176 | if (other.size != null) |
| 177 | return false; |
| 178 | } else if (!size.equals(other.size)) |
| 179 | return false; |
| 180 | if (status == null) { |
| 181 | if (other.status != null) |
| 182 | return false; |
| 183 | } else if (!status.equals(other.status)) |
| 184 | return false; |
| 185 | if (system == null) { |
| 186 | if (other.system != null) |
| 187 | return false; |
| 188 | } else if (!system.equals(other.system)) |
| 189 | return false; |
| 190 | if (vDC == null) { |
| 191 | if (other.vDC != null) |
| 192 | return false; |
| 193 | } else if (!vDC.equals(other.vDC)) |
| 194 | return false; |
| 195 | if (extendedInfo == null) { |
| 196 | if (other.extendedInfo != null) |
| 197 | return false; |
| 198 | } else if (!extendedInfo.equals(other.extendedInfo)) |
| 199 | return false; |
| 200 | return true; |
| 201 | } |
| 202 | |
| 203 | @Override |
| 204 | public String getName() { |
| 205 | return name; |
| 206 | } |
| 207 | |
| 208 | @Override |
| 209 | public URI getHref() { |
| 210 | return href; |
| 211 | } |
| 212 | |
| 213 | @Override |
| 214 | public Long getSize() { |
| 215 | return size; |
| 216 | } |
| 217 | |
| 218 | @Override |
| 219 | public String toString() { |
| 220 | return "[href=" + href + ", name=" + name + ", networkToAddresses=" + networkToAddresses + ", osType=" + osType |
| 221 | + ", operatingSystemDescription=" + operatingSystemDescription + ", resourceAllocationByType=" |
| 222 | + resourceAllocations + ", size=" + size + ", status=" + status + ", system=" + system + ", vDC=" + vDC |
| 223 | + ", extendedInfo=" + extendedInfo + "]"; |
| 224 | } |
| 225 | |
| 226 | @Override |
| 227 | public String getType() { |
| 228 | return TerremarkVCloudMediaType.VAPP_XML; |
| 229 | } |
| 230 | |
| 231 | @Override |
| 232 | public int compareTo(ReferenceType o) { |
| 233 | return (this == o) ? 0 : getHref().compareTo(o.getHref()); |
| 234 | } |
| 235 | |
| 236 | } |