| 1 | /** |
| 2 | * |
| 3 | * Copyright (C) 2011 Cloud Conscious, LLC. <info@cloudconscious.com> |
| 4 | * |
| 5 | * ==================================================================== |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * 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, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * ==================================================================== |
| 18 | */ |
| 19 | package org.jclouds.vcloud.domain.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | import java.util.Set; |
| 25 | |
| 26 | import org.jclouds.cim.ResourceAllocationSettingData; |
| 27 | import org.jclouds.cim.VirtualSystemSettingData; |
| 28 | import org.jclouds.vcloud.VCloudExpressMediaType; |
| 29 | import org.jclouds.vcloud.domain.ReferenceType; |
| 30 | import org.jclouds.vcloud.domain.Status; |
| 31 | import org.jclouds.vcloud.domain.VCloudExpressVApp; |
| 32 | |
| 33 | import com.google.common.collect.ListMultimap; |
| 34 | |
| 35 | /** |
| 36 | * |
| 37 | * @author Adrian Cole |
| 38 | * |
| 39 | */ |
| 40 | public class VCloudExpressVAppImpl implements VCloudExpressVApp { |
| 41 | private final String name; |
| 42 | private final URI href; |
| 43 | private final ReferenceType vDC; |
| 44 | private final Status status; |
| 45 | private final Long size; |
| 46 | private final ListMultimap<String, String> networkToAddresses; |
| 47 | private final String operatingSystemDescription; |
| 48 | private final VirtualSystemSettingData system; |
| 49 | private final Set<ResourceAllocationSettingData> resourceAllocations; |
| 50 | private final Integer osType; |
| 51 | |
| 52 | /** The serialVersionUID */ |
| 53 | private static final long serialVersionUID = 8464716396538298809L; |
| 54 | |
| 55 | public VCloudExpressVAppImpl(String name, URI href, Status status, Long size, ReferenceType vDC, |
| 56 | ListMultimap<String, String> networkToAddresses, Integer osType, String operatingSystemDescription, |
| 57 | VirtualSystemSettingData system, Set<ResourceAllocationSettingData> resourceAllocations) { |
| 58 | this.name = checkNotNull(name, "name"); |
| 59 | this.href = checkNotNull(href, "href"); |
| 60 | this.status = checkNotNull(status, "status"); |
| 61 | this.size = size; |
| 62 | this.vDC = vDC; |
| 63 | this.networkToAddresses = checkNotNull(networkToAddresses, "networkToAddresses"); |
| 64 | this.osType = osType; |
| 65 | this.operatingSystemDescription = operatingSystemDescription; |
| 66 | this.system = system; |
| 67 | this.resourceAllocations = checkNotNull(resourceAllocations, "resourceAllocations"); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public Status getStatus() { |
| 72 | return status; |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public ListMultimap<String, String> getNetworkToAddresses() { |
| 77 | return networkToAddresses; |
| 78 | } |
| 79 | |
| 80 | @Override |
| 81 | public Integer getOsType() { |
| 82 | return osType; |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public String getOperatingSystemDescription() { |
| 87 | return operatingSystemDescription; |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public VirtualSystemSettingData getSystem() { |
| 92 | return system; |
| 93 | } |
| 94 | |
| 95 | @Override |
| 96 | public Set<ResourceAllocationSettingData> getResourceAllocations() { |
| 97 | return resourceAllocations; |
| 98 | } |
| 99 | |
| 100 | @Override |
| 101 | public ReferenceType getVDC() { |
| 102 | return vDC; |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public int hashCode() { |
| 107 | final int prime = 31; |
| 108 | int result = 1; |
| 109 | result = prime * result + ((href == null) ? 0 : href.hashCode()); |
| 110 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 111 | result = prime * result + ((networkToAddresses == null) ? 0 : networkToAddresses.hashCode()); |
| 112 | result = prime * result + ((operatingSystemDescription == null) ? 0 : operatingSystemDescription.hashCode()); |
| 113 | result = prime * result + ((resourceAllocations == null) ? 0 : resourceAllocations.hashCode()); |
| 114 | result = prime * result + ((size == null) ? 0 : size.hashCode()); |
| 115 | result = prime * result + ((osType == null) ? 0 : osType.hashCode()); |
| 116 | result = prime * result + ((status == null) ? 0 : status.hashCode()); |
| 117 | result = prime * result + ((system == null) ? 0 : system.hashCode()); |
| 118 | result = prime * result + ((vDC == null) ? 0 : vDC.hashCode()); |
| 119 | return result; |
| 120 | } |
| 121 | |
| 122 | @Override |
| 123 | public boolean equals(Object obj) { |
| 124 | if (this == obj) |
| 125 | return true; |
| 126 | if (obj == null) |
| 127 | return false; |
| 128 | if (getClass() != obj.getClass()) |
| 129 | return false; |
| 130 | VCloudExpressVAppImpl other = (VCloudExpressVAppImpl) obj; |
| 131 | if (href == null) { |
| 132 | if (other.href != null) |
| 133 | return false; |
| 134 | } else if (!href.equals(other.href)) |
| 135 | return false; |
| 136 | if (name == null) { |
| 137 | if (other.name != null) |
| 138 | return false; |
| 139 | } else if (!name.equals(other.name)) |
| 140 | return false; |
| 141 | if (osType == null) { |
| 142 | if (other.osType != null) |
| 143 | return false; |
| 144 | } else if (!osType.equals(other.osType)) |
| 145 | return false; |
| 146 | if (networkToAddresses == null) { |
| 147 | if (other.networkToAddresses != null) |
| 148 | return false; |
| 149 | } else if (!networkToAddresses.equals(other.networkToAddresses)) |
| 150 | return false; |
| 151 | if (operatingSystemDescription == null) { |
| 152 | if (other.operatingSystemDescription != null) |
| 153 | return false; |
| 154 | } else if (!operatingSystemDescription.equals(other.operatingSystemDescription)) |
| 155 | return false; |
| 156 | if (resourceAllocations == null) { |
| 157 | if (other.resourceAllocations != null) |
| 158 | return false; |
| 159 | } else if (!resourceAllocations.equals(other.resourceAllocations)) |
| 160 | return false; |
| 161 | if (size == null) { |
| 162 | if (other.size != null) |
| 163 | return false; |
| 164 | } else if (!size.equals(other.size)) |
| 165 | return false; |
| 166 | if (status == null) { |
| 167 | if (other.status != null) |
| 168 | return false; |
| 169 | } else if (!status.equals(other.status)) |
| 170 | return false; |
| 171 | if (system == null) { |
| 172 | if (other.system != null) |
| 173 | return false; |
| 174 | } else if (!system.equals(other.system)) |
| 175 | return false; |
| 176 | if (vDC == null) { |
| 177 | if (other.vDC != null) |
| 178 | return false; |
| 179 | } else if (!vDC.equals(other.vDC)) |
| 180 | return false; |
| 181 | return true; |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public String getName() { |
| 186 | return name; |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public URI getHref() { |
| 191 | return href; |
| 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public Long getSize() { |
| 196 | return size; |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public String toString() { |
| 201 | return "[href=" + href + ", name=" + name + ", networkToAddresses=" + networkToAddresses + ", osType=" + osType |
| 202 | + ", operatingSystemDescription=" + operatingSystemDescription + ", resourceAllocationByType=" |
| 203 | + resourceAllocations + ", size=" + size + ", status=" + status + ", system=" + system + ", vDC=" + vDC |
| 204 | + "]"; |
| 205 | } |
| 206 | |
| 207 | @Override |
| 208 | public String getType() { |
| 209 | return VCloudExpressMediaType.VAPP_XML; |
| 210 | } |
| 211 | |
| 212 | @Override |
| 213 | public int compareTo(ReferenceType o) { |
| 214 | return (this == o) ? 0 : getHref().compareTo(o.getHref()); |
| 215 | } |
| 216 | |
| 217 | } |