| 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.internal; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | import java.util.Map; |
| 25 | |
| 26 | import org.jclouds.javax.annotation.Nullable; |
| 27 | |
| 28 | import org.jclouds.vcloud.VCloudMediaType; |
| 29 | import org.jclouds.vcloud.domain.CatalogItem; |
| 30 | import org.jclouds.vcloud.domain.ReferenceType; |
| 31 | |
| 32 | import com.google.common.collect.Maps; |
| 33 | |
| 34 | /** |
| 35 | * |
| 36 | * @author Adrian Cole |
| 37 | * |
| 38 | */ |
| 39 | public class CatalogItemImpl extends ReferenceTypeImpl implements CatalogItem { |
| 40 | |
| 41 | private final String description; |
| 42 | private final ReferenceType entity; |
| 43 | private final Map<String, String> properties = Maps.newLinkedHashMap(); |
| 44 | |
| 45 | public CatalogItemImpl(String name, URI id, @Nullable String description, ReferenceType entity, |
| 46 | Map<String, String> properties) { |
| 47 | super(name, VCloudMediaType.CATALOGITEM_XML, id); |
| 48 | this.description = description; |
| 49 | this.entity = checkNotNull(entity, "entity"); |
| 50 | this.properties.putAll(checkNotNull(properties, "properties")); |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public String getType() { |
| 55 | return VCloudMediaType.CATALOGITEM_XML; |
| 56 | } |
| 57 | |
| 58 | public ReferenceType getEntity() { |
| 59 | return entity; |
| 60 | } |
| 61 | |
| 62 | @Override |
| 63 | public String getDescription() { |
| 64 | return description; |
| 65 | } |
| 66 | |
| 67 | public Map<String, String> getProperties() { |
| 68 | return properties; |
| 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public String toString() { |
| 73 | return "CatalogItemImpl [id=" + getHref() + ", name=" + getName() + ", type=" + getType() + ", description=" |
| 74 | + getDescription() + ", entity=" + entity + ", properties=" + properties + "]"; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public int hashCode() { |
| 79 | final int prime = 31; |
| 80 | int result = super.hashCode(); |
| 81 | result = prime * result + ((description == null) ? 0 : description.hashCode()); |
| 82 | result = prime * result + ((entity == null) ? 0 : entity.hashCode()); |
| 83 | result = prime * result + ((properties == null) ? 0 : properties.hashCode()); |
| 84 | return result; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public boolean equals(Object obj) { |
| 89 | if (this == obj) |
| 90 | return true; |
| 91 | if (!super.equals(obj)) |
| 92 | return false; |
| 93 | if (getClass() != obj.getClass()) |
| 94 | return false; |
| 95 | CatalogItemImpl other = (CatalogItemImpl) obj; |
| 96 | if (description == null) { |
| 97 | if (other.description != null) |
| 98 | return false; |
| 99 | } else if (!description.equals(other.description)) |
| 100 | return false; |
| 101 | if (entity == null) { |
| 102 | if (other.entity != null) |
| 103 | return false; |
| 104 | } else if (!entity.equals(other.entity)) |
| 105 | return false; |
| 106 | if (properties == null) { |
| 107 | if (other.properties != null) |
| 108 | return false; |
| 109 | } else if (!properties.equals(other.properties)) |
| 110 | return false; |
| 111 | return true; |
| 112 | } |
| 113 | |
| 114 | } |