| 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.LinkedHashMap; |
| 25 | import java.util.Map; |
| 26 | |
| 27 | import org.jclouds.javax.annotation.Nullable; |
| 28 | |
| 29 | import org.jclouds.trmk.vcloud_0_8.domain.Catalog; |
| 30 | import org.jclouds.trmk.vcloud_0_8.domain.ReferenceType; |
| 31 | |
| 32 | /** |
| 33 | * Locations of resources in vCloud |
| 34 | * |
| 35 | * @author Adrian Cole |
| 36 | * |
| 37 | */ |
| 38 | public class CatalogImpl extends LinkedHashMap<String, ReferenceType> implements Catalog { |
| 39 | |
| 40 | /** The serialVersionUID */ |
| 41 | private static final long serialVersionUID = 8464716396538298809L; |
| 42 | private final String name; |
| 43 | private final String type; |
| 44 | private final URI href; |
| 45 | @Nullable |
| 46 | private final String description; |
| 47 | |
| 48 | public CatalogImpl(String name, String type, URI href, @Nullable String description, |
| 49 | Map<String, ReferenceType> contents) { |
| 50 | this.name = checkNotNull(name, "name"); |
| 51 | this.type = checkNotNull(type, "type"); |
| 52 | this.description = description; |
| 53 | this.href = checkNotNull(href, "href"); |
| 54 | putAll(checkNotNull(contents, "contents")); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * {@inheritDoc} |
| 59 | */ |
| 60 | @Override |
| 61 | public URI getHref() { |
| 62 | return href; |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * {@inheritDoc} |
| 67 | */ |
| 68 | @Override |
| 69 | public String getName() { |
| 70 | return name; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * {@inheritDoc} |
| 75 | */ |
| 76 | public String getDescription() { |
| 77 | return description; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * {@inheritDoc} |
| 82 | */ |
| 83 | @Override |
| 84 | public String getType() { |
| 85 | return type; |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public int hashCode() { |
| 90 | final int prime = 31; |
| 91 | int result = super.hashCode(); |
| 92 | result = prime * result + ((description == null) ? 0 : description.hashCode()); |
| 93 | result = prime * result + ((href == null) ? 0 : href.hashCode()); |
| 94 | result = prime * result + ((name == null) ? 0 : name.hashCode()); |
| 95 | result = prime * result + ((type == null) ? 0 : type.hashCode()); |
| 96 | return result; |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public boolean equals(Object obj) { |
| 101 | if (this == obj) |
| 102 | return true; |
| 103 | if (!super.equals(obj)) |
| 104 | return false; |
| 105 | if (getClass() != obj.getClass()) |
| 106 | return false; |
| 107 | CatalogImpl other = (CatalogImpl) obj; |
| 108 | if (description == null) { |
| 109 | if (other.description != null) |
| 110 | return false; |
| 111 | } else if (!description.equals(other.description)) |
| 112 | return false; |
| 113 | if (href == null) { |
| 114 | if (other.href != null) |
| 115 | return false; |
| 116 | } else if (!href.equals(other.href)) |
| 117 | return false; |
| 118 | if (name == null) { |
| 119 | if (other.name != null) |
| 120 | return false; |
| 121 | } else if (!name.equals(other.name)) |
| 122 | return false; |
| 123 | if (type == null) { |
| 124 | if (other.type != null) |
| 125 | return false; |
| 126 | } else if (!type.equals(other.type)) |
| 127 | return false; |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | @Override |
| 132 | public int compareTo(ReferenceType o) { |
| 133 | return (this == o) ? 0 : getHref().compareTo(o.getHref()); |
| 134 | } |
| 135 | |
| 136 | } |